[mingw - C/C++] popen(): possible to "background" subprocess?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[mingw - C/C++] popen(): possible to "background" subprocess?

SourceForge.net

Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=3189803
By: lionelb

Greetings,

I am developing a program using MinGW/gcc on Win2k which pipes commands to Gnuplot
(http://www.gnuplot.info/). This works fine if I use popen() to open a pipe
to a subprocess running pgnuplot.exe (the Win32 pipe version of the Gnuplot
binary).

Problem is that is that as soon as my program terminates, so does the subprocess;
I would like to be able to keep the Gnuplot window open - i.e. keep the subprocess
running after termination of the parent process, much as the system() call does.

I can achieve this eg. under Cygwin, using fork(), pipe(), exec(), dup2(), ...
by exec-ing pgnuplot.exe as a background process (using "&" in the command line
passed to exec()).

Can I achieve the same under MinGW via popen(). I suspect I might be able to
using the Win32 _pipe(), _spawn(), etc., but there lies a world of pain...

Any ideas appreciated,

--
Lionel B



______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=286529


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: [mingw - C/C++] popen(): possible to "background" subprocess?

Michael Gerdau
> I am developing a program using MinGW/gcc on Win2k which pipes commands to Gnuplot
> (http://www.gnuplot.info/). This works fine if I use popen() to open a pipe
> to a subprocess running pgnuplot.exe (the Win32 pipe version of the Gnuplot
> binary).
>
> Problem is that is that as soon as my program terminates, so does the subprocess;

AFAIK that's what popen() is supposed to do.

> I would like to be able to keep the Gnuplot window open - i.e. keep the subprocess
> running after termination of the parent process, much as the system() call does.

Then you probably have to do something like system()
(e.g. exec() and friends).

> I can achieve this eg. under Cygwin, using fork(), pipe(), exec(), dup2(), ...
> by exec-ing pgnuplot.exe as a background process (using "&" in the command line
> passed to exec()).
>
> Can I achieve the same under MinGW via popen().

I don't think so. It would be against what popen is supposed to do.
Under Cygwin you don't use popen to achieve that either (and there
is a reason ;-)

> I suspect I might be able to
> using the Win32 _pipe(), _spawn(), etc., but there lies a world of pain...

Since MinGW has no fork() I suppose the "world of pain" from above
is the way to go.

Hope you enjoy S&M ;-)
Michael
--
 Vote against SPAM - see http://www.politik-digital.de/spam/
 Michael Gerdau       email: [hidden email]
 GPG-keys available on request or at public keyserver

attachment0 (196 bytes) Download Attachment