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

后端 未结 2 650
小蘑菇
小蘑菇 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).

提交回复
热议问题