pipe related question

D

David Reed

Is there any way to have one program run another arbitrary program
with input from stdin and display the output as if you had run it in
a shell (i.e., you'd see some of the output followed by the input
they typed in and then a newline because they pressed return followed
by subsequent output, etc.).

I can't use readline with the pipe because I don't know how much
output the arbitrary program has before it calls an input statement.
I've googled and understand that calling read() will deadlock when
the program is waiting for input.

When I first write all the input to the input pipe and then call read
on the output pipe it works just the same as if I had run the program
as: program < input_file

What I'd like to see is the input intermixed with the output as if
the user had typed it in.

Thanks,
Dave
 
D

Donn Cave

Is there any way to have one program run another arbitrary program
with input from stdin and display the output as if you had run it in
a shell (i.e., you'd see some of the output followed by the input
they typed in and then a newline because they pressed return followed
by subsequent output, etc.).

I can't use readline with the pipe because I don't know how much
output the arbitrary program has before it calls an input statement.
I've googled and understand that calling read() will deadlock when
the program is waiting for input.

When I first write all the input to the input pipe and then call read
on the output pipe it works just the same as if I had run the program
as: program < input_file

What I'd like to see is the input intermixed with the output as if
the user had typed it in.

It sounds like there may be two problems here. You may need to
go to some extra lengths to get the arbitrary program to adopt
a convenient buffering strategy. I'm sure you have come across
plenty of discussion of this problem in your review of the old
traffic in this group, since it comes up all the time. The usual
answer is to use a pseudotty device instead of a regular pipe.
I don't know what's currently popular for Python support of this
device, but there's builtin support on some platforms, cf.
os.openpty and os.forkpty. It may be convenient in your case
to turn ECHO on.

The other problem is more intractable. If you want to know
for sure when the arbitrary program expects input, well, UNIX
doesn't support that. (Can you run your application on VMS?)
The only thing I can think of is a select() with timeout, with
some compromise value that will allow most outputs to complete
without stalling longer than is really convenient.

Donn Cave, (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top