Cross-platform redirect of standard input and output of spawned process in native C/C++ (edit with solution)

后端 未结 2 636
小蘑菇
小蘑菇 2020-12-17 21:49

I have a string command I\'d like to execute asynchronously while writing to its input and reading its output. Sounds easy, right, the devil is in the cross-platform. I\'m t

相关标签:
2条回答
  • 2020-12-17 21:58

    Give libexecstream a whirl. It's cross platform, and allows you to trap the input, output and error streams of a process asynchronously as C++ style streams.

    I've used it on Linux, Darwin and Windows and it seems to work. It's also pretty lightweight so integrates into projects with little pain, and has a pretty open BSD licence. I don't think there's any way around using a library (other than writing your own variations for each platform).

    0 讨论(0)
  • 2020-12-17 22:11

    for converting windows HANDLEs to C file descriptors use _open_osfhandle http://msdn.microsoft.com/en-us/library/bdts1c9x%28VS.71%29.aspx

    EDIT: this example once helped me aswell with a similar problem: http://www.halcyon.com/~ast/dload/guicon.htm

    0 讨论(0)
提交回复
热议问题