2

I try to start processes by script, which can interact.

EDIT: The general issue is to start these processes via php. After the process is started, another php-script (or the same running again) shall read the output of the process. Than a third php-script shall write to the input of the process. To simulate the start by php I did use a bash-script, because it has the same problems.

For this, I create an out-file, the process can write to, and a fifo, the process reads from. My process is, eg, passwd.

When I try it like this:

mkfifo fifo.my
touch out.my
passwd > out.my 2> out.my < fifo.my & echo $!

it does not work. According to this posting a EOF causes termination of the passwd-Process.

Following the solution of the mentioned posting, I tried

mkfifo fifo.my
touch out.my
cat > fifo.my &
passwd > out.my 2> out.my < fifo.my & echo $!

which creates two jobs which I can watch with

jobs

My target is, to start this via bash-script

#!/bin/bash
cat > fifo.my & PID=$!
echo $PID

When I do call the script, a Process with PID = $PID is created, but not a job. And, much more important,

passwd > out.my 2> out.my < fifo.my & echo $!

does not work, because again an EOF is send through the pipe.

How can I keep the pipe open from a script?

Francozen
  • 163
  • 5
kvogelsa
  • 21
  • 3

1 Answers1

0

I suggest using Tcl's "expect" library for this, especially for scripting passwd; it allocates a pseudo-terminal which removes most of the suprises, and lets you take action based on the results.

pjc50
  • 1,720
  • 10
  • 12
  • Well, I already had a look at expect. It does read from anywhere, too, doesn't it? So I would have to open a pipe for expect with the same issues – kvogelsa Jul 18 '12 at 13:32
  • I don't follow what you're saying; run expect at the top level and have it send data to the process, it handles all the pipe machinery for you. What, ultimately, are you trying to do? – pjc50 Jul 18 '12 at 16:12
  • I edited the post to explain my target. – kvogelsa Jul 19 '12 at 09:25