I'm wondering if it's possible to launch a Linux application from within my C application and be able to read and input data to that launched program. What functions should I be looking into to be able to do this. I know I can open applications with popen()
and can get details back in C, but I want to be able to input/output to this application for an extended period of time (the application I want to interact with ask for details and yes/no answers until its task is done). I am wanting to make a front end application which connects to a chat platform like IRC and be able to control the remote application from IRC or any other protocol I use. If possible I would like any examples written in Perl or C. Thanks for any details or links to other similar projects that I can use.
Asked
Active
Viewed 462 times
0

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278
-
A process A can launch a second process B and provide B with stdin/out/err streams that are connected to A. I do not believe it's possible for process A to somehow attach itself to the stdin/out/err streams of an existing process B that A did not launch itself (think of the security implications) _unless_ A and B use an IPC mechanism to coordinate the creation of these shared streams (which probably wouldn't be file descriptors 0, 1 and 2). – Jim Garrison Feb 01 '13 at 02:48
-
It appears that the user who asked this has lost interest in the answer, judging from the user's icon. It depends on the interaction model of the application, but it might well be possible with pseudo-ttys (think Perl and Expect module). – Jonathan Leffler Feb 01 '13 at 05:18
1 Answers
0
I suggest a Perl solution using IPC::Open2
as described in Bidirectional Communication with Another Process
in perldoc perlipc
. The synopsis looks like this
use IPC::Open2;
my($chld_out, $chld_in);
my $pid = open2($chld_out, $chld_in, 'some cmd and args');
after which you can
print $child_in "Input to child process\n";
my $response = <$chld_out>;

Borodin
- 126,100
- 9
- 70
- 144