473,486 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

set the stdin & stdout for an external program

Maybe I ask something OS depended but maybe not. So I ask:
I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?
Sorry for my bad english and THANKS
Aug 28 '05 #1
5 8956
<- Chameleon -> wrote:
Maybe I ask something OS depended but maybe not. So I ask:
I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?
Yes. It is system specific and off topic here.

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?


For Linux, you can use somthing like popen, however I'd probably do
somthing different. I'd probably call the system calls directly to
avoid the buffering through a FILE *.

For Windoes, "_popen" does exist.
Aug 28 '05 #2

<- Chameleon -> wrote:
Maybe I ask something OS depended but maybe not. So I ask:
I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?


If you want a one-way communication, that is when the parent process
only writes and the child only reads or vice versa, use popen. If you
want a two-way communication open two pipes in the parent process, fork
a child, replace STDIN_FILENO and STDOUT_FILENO (and probably
STDERR_FILENO) file descriptors with read and write ends of the two
pipes.

Here is example how it is done with STDIN_FILENO.
http://www.advancedlinuxprogramming....apter-5/dup2.c

Aug 29 '05 #3
>>Maybe I ask something OS depended but maybe not. So I ask:


I want to run an external program from my C++ program.
I want stdin of external program constructed from a C++ string in my
program.
I want stdout of external program constructs a C++ string in my program.

Is this possible without intermediate temporary files?

Its OT but if you know an OS depended call (for Win32 or Linux) can you
give it to me?

If you want a one-way communication, that is when the parent process
only writes and the child only reads or vice versa, use popen. If you
want a two-way communication open two pipes in the parent process, fork
a child, replace STDIN_FILENO and STDOUT_FILENO (and probably
STDERR_FILENO) file descriptors with read and write ends of the two
pipes.

Here is example how it is done with STDIN_FILENO.
http://www.advancedlinuxprogramming....apter-5/dup2.c


thanks but the problem is that the child process is in binary form. I
cannot change it.
I can change only my program (caller).
Aug 29 '05 #4

<- Chameleon -> wrote:

[]
thanks but the problem is that the child process is in binary form. I
cannot change it.


You don't need to change the child program. fork() in the parent
process, set up the file descriptors and exec("the child process is in
binary form", ...) in the child process.

Aug 29 '05 #5
This is done in the parent process.
PC: http://209.171.52.99/threads/process...asp?print=true
Linux: same concepts, different calls. e.g. see book Linux Socket
Programming.
I think google searches should get you what you need.

Stuart

Aug 29 '05 #6

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

Similar topics

10
8216
by: Sanyi Benczik | last post by:
Is there a standard way in C++ to call an external program or is this platform dependent? If it is platform dependent, can somebody drop a line what to use or where to look for info for GNU C++...
0
1803
by: lickspittle | last post by:
Hi, I have Python embedded with my other code, and when my other code opens a console and redirects stdout, stdin and stderr to it, then calls PyRun_InteractiveLoop, it immediately returns with...
8
2362
by: max(01)* | last post by:
hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: .... while True: try:
6
7981
by: Andrew | last post by:
Hello, I have read about stdin and stdout being standard input and output streams, but I am still having trouble visualizing how they really work and what they contain during program execution....
0
1365
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
4
2575
by: Lad | last post by:
How can I run external program from Python? I use Python with XP Thank you for help LB
4
11259
by: xman | last post by:
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...
7
2929
by: Benjamin Watine | last post by:
Hi the list, I need to send a var to stdin of an external soft ("cat" command for example). How can I do this ? I would like a function like that : theFunction ('cat -', stdin=myVar) I...
3
4702
by: ckkart | last post by:
Hi, on XP when starting a certain external program (plain C calculation program which communicates via stdout/fs) from python 2.5 using subprocess.Popen the external program crashes. It does not...
0
7105
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,...
0
6967
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...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
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...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5439
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,...
1
4870
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...
0
4564
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...
0
1381
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 ...

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.