forked from qt-creator/qt-creator
Process: Introduce DetachedChannelMode enum
The default impl of Process::startDetached() forwards process channels. Make it optional by providing an additional argument of DetachedChannelMode type for Process::startDetached(). Change-Id: I6cb55377c21dfedacd53117756894d07e354e0fe Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -41,6 +41,11 @@ enum class Channel {
|
||||
Error
|
||||
};
|
||||
|
||||
enum class DetachedChannelMode {
|
||||
Forward,
|
||||
Discard
|
||||
};
|
||||
|
||||
enum class TextChannelMode {
|
||||
// Keep | Emit | Emit
|
||||
// raw | text | content
|
||||
|
@@ -1317,12 +1317,18 @@ void Process::closeWriteChannel()
|
||||
d->sendControlSignal(ControlSignal::CloseWriteChannel);
|
||||
}
|
||||
|
||||
bool Process::startDetached(const CommandLine &cmd, const FilePath &workingDirectory, qint64 *pid)
|
||||
bool Process::startDetached(const CommandLine &cmd, const FilePath &workingDirectory,
|
||||
DetachedChannelMode channelMode, qint64 *pid)
|
||||
{
|
||||
return QProcess::startDetached(cmd.executable().toUserOutput(),
|
||||
cmd.splitArguments(),
|
||||
workingDirectory.toUserOutput(),
|
||||
pid);
|
||||
QProcess process;
|
||||
process.setProgram(cmd.executable().toUserOutput());
|
||||
process.setArguments(cmd.splitArguments());
|
||||
process.setWorkingDirectory(workingDirectory.toUserOutput());
|
||||
if (channelMode == DetachedChannelMode::Discard) {
|
||||
process.setStandardOutputFile(QProcess::nullDevice());
|
||||
process.setStandardErrorFile(QProcess::nullDevice());
|
||||
}
|
||||
return process.startDetached(pid);
|
||||
}
|
||||
|
||||
void Process::setLowPriority()
|
||||
|
@@ -137,6 +137,7 @@ public:
|
||||
// Some of them could be aggregated in another public utils class.
|
||||
|
||||
static bool startDetached(const CommandLine &cmd, const FilePath &workingDirectory = {},
|
||||
DetachedChannelMode channelMode = DetachedChannelMode::Forward,
|
||||
qint64 *pid = nullptr);
|
||||
|
||||
// Starts the command and waits for finish.
|
||||
|
Reference in New Issue
Block a user