I am trying to write a shell script that starts a program, reads from its stdout and can write to its stdin.
I'm having trouble to get it to work, I tried using named pipes, and using exec and file descriptors.
Just couldn't get it to work, so I thought I'll post it here to see if someone is willing to help me.
The program is called primes, and it first asks for my name
Sure, I can show, but I had many versions and just in general have no clue how to do this.
I'm currently trying to create a named pipe for the input, so that I can write to that in my script (> $pipe).
Then I'm running the primes program in the background, which gets the $pipe on stdin.
I did a tail -f there to keep it opened, otherwise the stream would close when I write to it with for instance echo "test name" > $pipe.
But, it doesn't work, and I'm also not even sure how to debug this.
------ Post updated at 03:00 PM ------
Now using this version. I thought I should perhaps not background the program. But this also doesn't seem to work.
This version does not output anything when I start it ... (not seeing the "read: ..." and also not seeing any output of the program).
The first question i have is: how exactly is the program reading the input?
If this is done via the gets() the problem might be a missing EOL ("\n") or EOF character at the end of the input line. Some programs (i.e. passwd also clear their <stdin> to make sure that redirection does not take place. Your program might have a similar mechanism in place.
Other than that: you might want to explore the "coprocess-facility" of the Korn shell if you want to bidirectionally communicate with asynchronously running jobs. If i remember correctly some versions of bash have that too now, but i have no experience with this in bash. It seems to work slightly different there than in Korn shell.
I hope this helps.
bakunin
Last edited by RudiC; 11-25-2018 at 05:57 PM..
Reason: corrected ICODE tag
I followed the directions here
Free Twitter Source Code ? Twitter Database Server: Install
and created a php script that enters twitter keyword searches into a MySQL DB.
When you execute the files outlined in the above link, a script starts indefinitely.
I've noticed that the scripts... (6 Replies)
shell script in Unix/Linux to find the lines numbers of a text file are having word which is 5 to 10 characters long and having first letter as a capital letter. (3 Replies)
Hi,
I wanted to write a schell program that fetches the values from a file and prints the output as its onerall multiplication.
for example I have a file named abc. it has values 2, 3, 4
now my program should give me 2*3*4 ie 24.
note:this file abc can have any numbers.
so experts,... (9 Replies)
Hi Everybody,
I'm trying to create a script that will launch firefox from a bash shell in ubuntu and perform certain tasks.
Why does it have to be a script? Because this firefox must eventually run in a server with xvfb (no gnome, no kde), so I will not have access to it through the GUI.
At... (2 Replies)
I have created a ksh shell script and used it as a login shell for a user.
</etc/passwd>
lramirev:x:111:200:Luis:/export/home/menush:/usr/local/menush/menush
My shell script is like this:
</usr/local/menush/menush>
#!/bin/ksh
#
if ]
then
. $HOME/.profile
fi
... (8 Replies)
Hi Everybody,
I previously posted this under Unix for dummies and got no answers, so here goes again:
I'm trying to create a script that will launch firefox from a bash shell in ubuntu and perform certain tasks.
Why does it have to be a script? Because this firefox must eventually run in a... (0 Replies)
#!/bin/csh
# This program will add integers
#
#
# add integer1 ..
#
# Check for argument
if ($#argv == 0 ) then
echo "usage: add integers"
exit 1
else
set input = $argv
endif
#
set sum = 0
foreach var ( $input )
@sum = $sum + $input
end
# (1 Reply)
hi
I want to call a shell script in C program
the script is : ssh -t user@remote sh /<remote>home/user/<file_name>.sh
and other several commands
C program : Call this script and the retrive the task that is been done in <file_name>.sh file
can any one tell me how... (5 Replies)