2014-11-27 18:31:09 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2014 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2014-11-27 18:31:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "CommandProcess.h"
|
|
|
|
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
CommandProcess::CommandProcess(QString command, QStringList arguments, QString input)
|
2024-07-26 22:53:52 +00:00
|
|
|
: m_Command(command),
|
2024-07-16 13:36:44 +00:00
|
|
|
m_Arguments(arguments),
|
2024-10-17 18:04:35 +00:00
|
|
|
m_Input(input)
|
|
|
|
|
{
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QString CommandProcess::run()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
QProcess process;
|
|
|
|
|
process.setReadChannel(QProcess::StandardOutput);
|
|
|
|
|
process.start(m_Command, m_Arguments);
|
|
|
|
|
bool success = process.waitForStarted();
|
|
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
QString output;
|
|
|
|
|
QString error;
|
2024-07-02 19:07:06 +00:00
|
|
|
if (success) {
|
|
|
|
|
if (!m_Input.isEmpty()) {
|
|
|
|
|
process.write(m_Input.toStdString().c_str());
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (process.waitForFinished()) {
|
2024-08-07 14:05:18 +00:00
|
|
|
output = process.readAllStandardOutput().trimmed();
|
2024-07-02 19:07:06 +00:00
|
|
|
error = process.readAllStandardError().trimmed();
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
if (int code = process.exitCode(); !success || code != 0) {
|
|
|
|
|
qFatal(
|
2024-10-17 18:04:35 +00:00
|
|
|
"command failed: %s %s\ncode: %d\nerror: %s", qUtf8Printable(m_Command), qUtf8Printable(m_Arguments.join(" ")),
|
|
|
|
|
code, error.isEmpty() ? "none" : qUtf8Printable(error)
|
|
|
|
|
);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2024-10-21 04:08:10 +00:00
|
|
|
Q_EMIT finished();
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return output;
|
2014-11-27 18:31:09 +00:00
|
|
|
}
|