forked from qt-creator/qt-creator
Utils: Return a bit more data from DeviceShell::runInShell
Pass on stderr data and exit code to the caller, it's typically in a better condition to handle errors. Use it to notify the user about non-available 'find' arguments and fix the fallback to ls-based operation. Change-Id: I535535de2ffa09cad1dd6e9b07eb69f807dbae2f Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -174,31 +174,11 @@ DeviceShell::~DeviceShell()
|
||||
* \param stdInData Data to send to the stdin of the command
|
||||
* \return true if the command finished with EXIT_SUCCESS(0)
|
||||
*
|
||||
* Runs the cmd inside the internal shell process and return whether it exited with EXIT_SUCCESS
|
||||
* Runs the cmd inside the internal shell process and return stdout, stderr and exit code
|
||||
*
|
||||
* Will automatically defer to the internal thread
|
||||
*/
|
||||
bool DeviceShell::runInShell(const CommandLine &cmd, const QByteArray &stdInData)
|
||||
{
|
||||
QTC_ASSERT(m_shellProcess, return false);
|
||||
Q_ASSERT(QThread::currentThread() != &m_thread);
|
||||
|
||||
const RunResult result = run(cmd, stdInData);
|
||||
return result.exitCode == 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief DeviceShell::outputForRunInShell
|
||||
* \param cmd The command to run
|
||||
* \param stdInData Data to send to the stdin of the command
|
||||
* \return The stdout of the command
|
||||
*
|
||||
* Runs a command inside the running shell and returns the stdout that was generated by it.
|
||||
*
|
||||
* Will automatically defer to the internal thread
|
||||
*/
|
||||
DeviceShell::RunResult DeviceShell::outputForRunInShell(const CommandLine &cmd,
|
||||
const QByteArray &stdInData)
|
||||
RunResult DeviceShell::runInShell(const CommandLine &cmd, const QByteArray &stdInData)
|
||||
{
|
||||
QTC_ASSERT(m_shellProcess, return {});
|
||||
Q_ASSERT(QThread::currentThread() != &m_thread);
|
||||
@@ -210,7 +190,7 @@ DeviceShell::State DeviceShell::state() const { return m_shellScriptState; }
|
||||
|
||||
QStringList DeviceShell::missingFeatures() const { return m_missingFeatures; }
|
||||
|
||||
DeviceShell::RunResult DeviceShell::run(const CommandLine &cmd, const QByteArray &stdInData)
|
||||
RunResult DeviceShell::run(const CommandLine &cmd, const QByteArray &stdInData)
|
||||
{
|
||||
if (m_shellScriptState == State::NoScript) {
|
||||
// Fallback ...
|
||||
@@ -539,16 +519,16 @@ void DeviceShell::onReadyRead()
|
||||
QTC_ASSERT(itCmd != m_commandOutput.end(), continue);
|
||||
|
||||
switch (type) {
|
||||
case Utils::DeviceShell::ParseType::StdOut:
|
||||
case ParseType::StdOut:
|
||||
itCmd->stdOut.append(data);
|
||||
break;
|
||||
case Utils::DeviceShell::ParseType::StdErr:
|
||||
case ParseType::StdErr:
|
||||
itCmd->stdErr.append(data);
|
||||
break;
|
||||
case Utils::DeviceShell::ParseType::ExitCode: {
|
||||
case ParseType::ExitCode: {
|
||||
bool ok = false;
|
||||
int exitCode;
|
||||
exitCode = QString::fromUtf8(data.begin(), data.size()).toInt(&ok);
|
||||
exitCode = data.toInt(&ok);
|
||||
QTC_ASSERT(ok, exitCode = -1);
|
||||
itCmd->exitCode = exitCode;
|
||||
itCmd->waiter->wakeOne();
|
||||
|
||||
Reference in New Issue
Block a user