473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

pipe related question


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

Nov 22 '05 #1
1 1259
In article <ma**************************************@python.o rg>,
David Reed <dr******@columbus.rr.com> wrote:
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, do**@u.washington.edu
Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rajarshi Guha | last post by:
Hi, I'm having a little trouble when I read from a named pipe. I create a pipe by os.mkfifo('/tmp/mypipe') and then open it for reading with fin = open('/tmp/mypipe','r+')
6
by: Carson | last post by:
Hi, How to write c code such that it supports pipe in? i.e., echo "ABCD" | a.out (how to write a c-code which generates the binaries a.out that can take the pipe in input for further...
4
by: Pascal Ehlert | last post by:
I don't know if this is the right newsgroup because the question is maybe a bit linux specific so if not slap me ;-) I'm trying to send the output of a perl-script to a socket. So I'm opening a...
0
by: Nick | last post by:
hi,all I have a question about named pipe. How does the pipe server know the client closed the connection? We can refer the example for CreateNamedPipe() function in MSDN. In block mode, once...
2
by: FB's .NET Dev PC | last post by:
I am writing two services in VB.NET, one of which needs to send text strings to the other. After reading, I decided (perhaps incorrectly) that named pipes would be the best interprocess...
11
by: 7stud | last post by:
Hi, Can someone explain what a broken pipe is? The following produces a broken pipe error: ---------- import subprocess as sub p = sub.Popen(, stdin=sub.PIPE, stdout=sub.PIPE)
6
by: kotzkroete | last post by:
Hi, I just started working on a simple 'more' version. I use it like this: cat blabla.txt | more Here is my problem: Since more gets its input through a pipe I can't use stdin for keyboard...
1
by: dgk | last post by:
I trying to use a named pipe but can't figure out how to get the callback to work: Module Module1 Private ps As System.IO.Pipes.NamedPipeServerStream Public Sub main()...
16
by: orajit | last post by:
I have created one file c;/temp/test.txt 000|23102007 001|21102007|23102007|GB11223344 001|20102007|22102007|GB11223345 001|19102007|22102007|GB11223346 999|3 The highlighted text are...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.