I want to execute a sub-process in C++. I need it to work on Windows and Linux. Is there such a function in Boost? What is the standard way of doing it?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- How do you make an installer for your python progr
- Selecting only the first few characters in a strin
- Libgdx - Check if a key is being held down?
- What exactly do pointers store? (C++)
ANSI C89
system()
exists on both platforms. Obviously what that process does depends on whether it works portably between platforms. But you certainly don't need boost to do it.There is the not-yet-approved Boost.Process library. I never tried it, but it may do the job for you.
I've successfully used Poco's Process API though.
What level of control do you want? The standard includes
system()
, which can execute a sub-process. If you want to control standard input or standard output, you can usepopen
(though MS usually calls it_popen
). You only really need to look elsewhere if you want something more elaborate than that.Poco and ACE have Process classes that do what you want. See Foundation->Processes->Process in Poco; Process.h/Process.cpp for Ace. I wouldn't be surprised if QT has something similar.
As for how to do it, basically you wrap the OS dependencies and bury the details. Poco and Ace offer contrasting common methods. Poco tends to handle things by writing implementation objects (xxx_impl) for each platform with the proper one getting pulled in depending on the OS. ACE seems to #ifdef the code, sometimes to the point of madness, though in fairness it has been a long time since I looked at that code.