473,670 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1269
In article <ma************ *************** ***********@pyt hon.org>,
David Reed <dr******@colum bus.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.washingt on.edu
Nov 23 '05 #2

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

Similar topics

4
7460
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
2437
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 processing?)
4
26843
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 pipe to the program (FILE fp = popen("foobar.pl", "r")) and read and write it directly to the socket.. This is my code: ------ while(!feof(fp)) { bytes = fread(b,1,1024,fp); fwrite(b,1,bytes,sock);
0
1437
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 ConnectNamedPipe() returns, it means the client called CreateFile(), and after finish reading and writing, client call CloseHandle(), at this point, how does the pipe server know the pipe has been closed? And if client did not call CloseHandle(),...
2
5058
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 communication method for this task. I set about creating, on the pipe's server side, a new thread which would instantiate a blocking inbound message pipe, and the client side which would write to that pipe when needed. Being on the same PC, security is...
11
21292
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
2418
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 input anymore and thus can't scroll with space and return. How can I have one filestream for the pipe and another for regular
1
5534
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() Application.EnableVisualStyles() Try ps = New System.IO.Pipes.NamedPipeServerStream("Test") ps.BeginWaitForConnection(AddressOf HandleConnection, "Test")
16
2253
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 started date and end date and account number .
0
8468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8660
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7415
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.