0

I want to create a cross platform (windows, mac, linux) C application that is capable of spawning a subprocess and capturing the stdin, stdout and stderr simultaneously.

I know it's possible to do something like this with popen in unix, StackOverflow

and in windows with the WinAPI, MSDN

I also understand that it is possible to redirect the outputs to files and read from there, but redirecting the standard pipes does seem like a very basic standard library feature.

Did I miss a basic function and/or is there any lightweight crossplatform library that I can use to achieve this goal without significant complexity?

Community
  • 1
  • 1
Work of Artiz
  • 1,085
  • 7
  • 16
  • If you want to use *all* the standard streams (input, output and error) then no it's not possible with `popen` (which exists in Windows too). And there's no common functionality between Windows and POSIX (Linux and OSX) platforms for this either, so you have to use conditional compilation with the preprocessor. And lastly, we won't give you help finding a library, as that's off-topic for SO (but we will gladly help you if you find a library and have trouble with that). – Some programmer dude Dec 31 '15 at 15:39
  • excuse me `execl`, I did like the code sample one of the answers gave. (for future reference [Github](https://github.com/sni/mod_gearman/blob/master/common/popenRWE.c)) which could be merged with the msdn answer using the preprocessor. Glib is perfect for this job though – Work of Artiz Dec 31 '15 at 15:49

1 Answers1

1

The glib library provides what you want. Here is the documentation of its process API: https://developer.gnome.org/glib/stable/glib-Spawning-Processes.html

mikedu95
  • 1,725
  • 2
  • 12
  • 24