Hi all,
this is my first message here

I have some hard time since two days with a (maybe) simple problem: I want to communication with a subprocess (say ftp for example) to send it commands, and to read its answers.
The first way I explored was file descriptors. I didn't found a way. FIFOs sound promising but, as you will see, I'm stuck.
By the way: I don't want to use the 'expect' program. 'expect' is designed to solve this kind of problem, but my problem isn't only interaction, and I don't want to learn yet another programming language (I'm not a programmer, only a sysadmin).
The scenario:
- launch the desired program (ftp in this example)
- send it a command (help)
- read the answer
- send another command (verbose)
- read the answer
- send another command (bye)
My problem is very simple: when I send a command with 'echo' (or with 'cat', same result), bash seems to close the corresponding FIFO. Then the launched program terminates. When I read the output, same problem.
Here is an example:
Code:
#!/bin/bash
TMPDIR=$(mktemp -d) || { echo "mktemp error"; exit -1; }
FIFO_STDIN=$TMPDIR/fifo_stdin
FIFO_STDOUT=$TMPDIR/fifo_stdout
mkfifo $FIFO_STDIN $FIFO_STDOUT || { echo "mkfifo error"; rm -rf $TMPDIR; exit -1; }
ftp <$FIFO_STDIN >$FIFO_STDOUT 2>&1 &
echo 'help' >$FIFO_STDIN
# the ftp program is already stopped here
read TEXT <$FIFO_STDOUT
echo "[$TEXT]"
echo 'verbose' >$FIFO_STDIN
read TEXT <$FIFO_STDOUT
echo "[$TEXT]"
echo 'bye' >$FIFO_STDIN
rm -rf $TMPDIR
exit 0
Anyone have an idea to keep the FIFOs open ? And/or another way to communicate ?
I also tested with this kind of stuff:
Code:
exec 5>&1
exec 6<&2
ftp >&5 <&6 2>&1 &
etc etc
But no more result.