OpenMS
2.6.0
|
A wrapper around QProcess to conveniently start an external program and forward its outputs. More...
#include <OpenMS/SYSTEM/ExternalProcess.h>
Public Types | |
enum | RETURNSTATE { SUCCESS, NONZERO_EXIT, CRASH, FAILED_TO_START } |
result of calling an external executable More... | |
Public Member Functions | |
ExternalProcess () | |
default Ctor; callbacks for stdout/stderr are empty More... | |
ExternalProcess (std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr) | |
set the callback functions to process stdout and stderr output when the external process generates it More... | |
~ExternalProcess () | |
D'tor. More... | |
void | setCallbacks (std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr) |
re-wire the callbacks used using run() More... | |
RETURNSTATE | run (const QString &exe, const QStringList &args, const QString &working_dir, const bool verbose, String &error_msg) |
Runs a program and calls the callback functions from time to time if output from the external program is available. More... | |
ExternalProcess::RETURNSTATE | run (const QString &exe, const QStringList &args, const QString &working_dir, const bool verbose) |
Same as other overload, just without a returned error message. More... | |
Private Slots | |
void | processStdOut_ () |
void | processStdErr_ () |
Private Attributes | |
QProcess * | qp_ |
pointer to avoid including the QProcess header here (it's huge) More... | |
std::function< void(const String &)> | callbackStdOut_ |
std::function< void(const String &)> | callbackStdErr_ |
A wrapper around QProcess to conveniently start an external program and forward its outputs.
Use the custom Ctor to provide callback functions for stdout/stderr output or set them via setCallbacks().
Running an external program blocks the caller, so do not use this in a main GUI thread (unless you have some other means to tell the user that no interaction is possible at the moment).
@Note If you want QMessageboxes to be shown if something went wrong, use ExternalProcessMBox as a convenient wrapper instead.
|
strong |
ExternalProcess | ( | ) |
default Ctor; callbacks for stdout/stderr are empty
ExternalProcess | ( | std::function< void(const String &)> | callbackStdOut, |
std::function< void(const String &)> | callbackStdErr | ||
) |
set the callback functions to process stdout and stderr output when the external process generates it
~ExternalProcess | ( | ) |
D'tor.
|
privateslot |
|
privateslot |
ExternalProcess::RETURNSTATE run | ( | const QString & | exe, |
const QStringList & | args, | ||
const QString & | working_dir, | ||
const bool | verbose | ||
) |
Same as other overload, just without a returned error message.
RETURNSTATE run | ( | const QString & | exe, |
const QStringList & | args, | ||
const QString & | working_dir, | ||
const bool | verbose, | ||
String & | error_msg | ||
) |
Runs a program and calls the callback functions from time to time if output from the external program is available.
exe | The program to call (can contain spaces in path, no problem) | |
args | A list of extra arguments (can be empty) | |
verbose | Report the call command and errors via the callbacks (default: false) | |
working_dir | Execute the external process in the given directory (relevant when relative input/output paths are given). Leave empty to use the current working directory. | |
[out] | error_string | Message to display to the user if something went wrong (if return != SUCCESS) |
void setCallbacks | ( | std::function< void(const String &)> | callbackStdOut, |
std::function< void(const String &)> | callbackStdErr | ||
) |
re-wire the callbacks used using run()
|
private |
|
private |