Reputation: 13853
To run a command line using C++, I always use system
command. However, I think this way is too error-prone since I only can parse a char*
as argument without any other information. So I'm looking for a cross-platform library that works well with command-line? Has anyone known one?
Thanks,
Chan
Upvotes: 4
Views: 584
Reputation: 55554
Have a look at Boost.Process. It is still work in progress and is not part of the official Boost yet, but looks promising.
Upvotes: 4
Reputation: 11140
QProcess from Qt does this in a cross-platform manner.
http://doc.qt.nokia.com/4.6/qprocess.html
From the documentation above, the example usage is:
// some parent object
QObject * parent;
QString program = "./path/to/Qt/examples/widgets/analogclock";
QStringList arguments;
arguments << "-style" << "motif";
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);
Upvotes: 2