473,804 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C/C++ library to access a process's stdin and stdout?

I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.

May 13 '07 #1
4 11293
On May 13, 10:02 pm, xman <cshin...@gmail .comwrote:
I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.
Is the external program already running or does your program start the
external program.

In general there is no C++ standard (and so off topic here) way to do
what you ask but Linux/Unix machines use "popen" and I think Win32 has
a similar _popen function.
http://msdn2.microsoft.com/en-us/lib...4b(VS.80).aspx

Any further questions should be directed to a more relevant news
group.
May 13 '07 #2
Hi,

Using unix/linux you can do this by closing 0 (input) and 1 (output)
close(0) close(1) in combination with pipe. Then fork another process
(which inherits its parents file descriptors and use the other and of the
pipe created. Sincd file desciptors are assigned beginning with the lowest
available stdin and stdout will be assigned to the pipe.
Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"xman" <cs******@gmail .comwrote in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.

May 13 '07 #3


In additon, a little googling for pipe, close, open gives:

http://www.cs.sunysb.edu/~cse533/asgn1/pipes.html

Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"Ron AF Greve" <ron@localhostw rote in message
news:46******** *************@n ews.xs4all.nl.. .
Hi,

Using unix/linux you can do this by closing 0 (input) and 1 (output)
close(0) close(1) in combination with pipe. Then fork another process
(which inherits its parents file descriptors and use the other and of the
pipe created. Sincd file desciptors are assigned beginning with the lowest
available stdin and stdout will be assigned to the pipe.
Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"xman" <cs******@gmail .comwrote in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
>I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.


May 13 '07 #4
xman a écrit :
I'm looking for a C/C++ library that can get access to the stdin and
stdout of a process. I may invoke a external program in a C/C++
program, but how do write data into the stdin of the external program,
and read data out from the stdout of the external program?

Suggestions are much appreciated.
I have used pstream with success. It is basically a wrapper around
popen/pclose.

See: http://pstreams.sourceforge.net/

Michael
May 14 '07 #5

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

Similar topics

12
2488
by: JD | last post by:
This is another Python problem, I think might be unrelated to the earlier bug I found, and eventually figured out how to report it to Sourceforge. This is related to a question I have about Python hanging up either from a shell, or by importing a module. This I would not consider a bug, but more on my inexperience with Python. If my code causes Python to just hang up, and not allowing me to break out with control-C or...
18
4897
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
6
2235
by: ccdrbrg | last post by:
What is the best way to protect stdin within a library? I am writing a terminal based program that provides plugin capability using the dlopen() API. Sequencing program commands (typed) and library input prompts will not happen if stdin is supplied by pipe or redirection. So, I would like to include a statement in the pluggin
13
5130
by: bayer.justin | last post by:
Hi, I am trying to communicate with a subprocess via the subprocess module. Consider the following example: <subprocess.Popen object at 0x729f0> Here hey is immediately print to stdout of my interpreter, I did not type in the "hey". But I want to read from the output into a string, so I do
2
6280
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import os import sys file = os.popen("nslookup", 'w') file.write("google.com\n") file.close()
12
4542
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's finished, and if it is look at its output. I may want to send a signal at some point to kill the process. This seems straightforward, but it doesn't seem to be working. Here's my test case:
4
4506
by: rdabane | last post by:
Hi, I'm trying to perform following operation from inside the python script 1. Open a shell ( start a process ) 2. Send command1 to the process 3. Get output from the process 4. Send command2 to the process 5. Get output from the process .......
0
1998
by: Gabriel Genellina | last post by:
En Thu, 25 Sep 2008 09:49:31 -0300, Almar Klein <almar.klein@gmail.com> escribió: Use subprocess.PIPE Usually the tricky part is to figure out exactly whether there is more input or not. With Python it's easy, use the ps1 prompt. --- begin --- import sys
7
6240
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
9571
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
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
10069
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
6845
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
5505
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...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.