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:
Jarek Kobus
2024-06-26 10:44:34 +02:00
parent a6b7473834
commit 11905967fe
3 changed files with 17 additions and 5 deletions

View File

@@ -41,6 +41,11 @@ enum class Channel {
Error
};
enum class DetachedChannelMode {
Forward,
Discard
};
enum class TextChannelMode {
// Keep | Emit | Emit
// raw | text | content

View File

@@ -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()

View File

@@ -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.