forked from qt-creator/qt-creator
SSH: Fix running remote process in terminal
ConsoleProcess stumbles over the special characters in the remote command and as a result silently runs the command locally instead. Prevent that. We can (and should) simply leave these characters alone, as they have no special meaning on the local machine. Change-Id: I31b3afe1cf170e51d431372b15f4df3656006959 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -70,7 +70,9 @@ public:
|
||||
QProcess::ProcessError error() const;
|
||||
QString errorString() const;
|
||||
|
||||
bool start(const QString &program, const QString &args);
|
||||
enum class MetaCharMode { Abort, Ignore };
|
||||
bool start(const QString &program, const QString &args,
|
||||
MetaCharMode metaCharMode = MetaCharMode::Ignore);
|
||||
public slots:
|
||||
void stop();
|
||||
|
||||
|
@@ -65,7 +65,7 @@ void ConsoleProcess::setSettings(QSettings *settings)
|
||||
d->m_settings = settings;
|
||||
}
|
||||
|
||||
bool ConsoleProcess::start(const QString &program, const QString &args)
|
||||
bool ConsoleProcess::start(const QString &program, const QString &args, MetaCharMode metaCharMode)
|
||||
{
|
||||
if (isRunning())
|
||||
return false;
|
||||
@@ -75,7 +75,8 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
|
||||
|
||||
QtcProcess::SplitError perr;
|
||||
QtcProcess::Arguments pargs = QtcProcess::prepareArgs(args, &perr, HostOsInfo::hostOs(),
|
||||
&d->m_environment, &d->m_workingDir);
|
||||
&d->m_environment, &d->m_workingDir,
|
||||
metaCharMode == MetaCharMode::Abort);
|
||||
QString pcmd;
|
||||
if (perr == QtcProcess::SplitOk) {
|
||||
pcmd = program;
|
||||
|
@@ -51,8 +51,10 @@ qint64 ConsoleProcess::applicationMainThreadID() const
|
||||
return d->m_appMainThreadId;
|
||||
}
|
||||
|
||||
bool ConsoleProcess::start(const QString &program, const QString &args)
|
||||
bool ConsoleProcess::start(const QString &program, const QString &args, MetaCharMode metaCharMode)
|
||||
{
|
||||
Q_UNUSED(metaCharMode);
|
||||
|
||||
if (isRunning())
|
||||
return false;
|
||||
|
||||
|
@@ -595,12 +595,12 @@ static QString quoteArgWin(const QString &arg)
|
||||
}
|
||||
|
||||
QtcProcess::Arguments QtcProcess::prepareArgs(const QString &cmd, SplitError *err, OsType osType,
|
||||
const Environment *env, const QString *pwd)
|
||||
const Environment *env, const QString *pwd, bool abortOnMeta)
|
||||
{
|
||||
if (osType == OsTypeWindows)
|
||||
return prepareArgsWin(cmd, err, env, pwd);
|
||||
else
|
||||
return Arguments::createUnixArgs(splitArgs(cmd, osType, true, err, env, pwd));
|
||||
return Arguments::createUnixArgs(splitArgs(cmd, osType, abortOnMeta, err, env, pwd));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -79,7 +79,8 @@ public:
|
||||
//! Prepare argument of a shell command for feeding into QProcess
|
||||
static Arguments prepareArgs(const QString &cmd, SplitError *err,
|
||||
OsType osType = HostOsInfo::hostOs(),
|
||||
const Environment *env = nullptr, const QString *pwd = nullptr);
|
||||
const Environment *env = nullptr, const QString *pwd = nullptr,
|
||||
bool abortOnMeta = true);
|
||||
//! Prepare a shell command for feeding into QProcess
|
||||
static bool prepareCommand(const QString &command, const QString &arguments,
|
||||
QString *outCmd, Arguments *outArgs, OsType osType = HostOsInfo::hostOs(),
|
||||
|
@@ -201,7 +201,8 @@ void SshDeviceProcess::handleConnected()
|
||||
this, &SshDeviceProcess::handleProcessStarted);
|
||||
connect(&d->consoleProcess, &ConsoleProcess::stubStopped,
|
||||
this, [this] { handleProcessFinished(d->consoleProcess.errorString()); });
|
||||
d->consoleProcess.start(cmdLine.first(), cmdLine.mid(1).join(' '));
|
||||
d->consoleProcess.start(cmdLine.first(), cmdLine.mid(1).join(' '),
|
||||
ConsoleProcess::MetaCharMode::Ignore);
|
||||
} else {
|
||||
connect(d->process.get(), &QSsh::SshRemoteProcess::started,
|
||||
this, &SshDeviceProcess::handleProcessStarted);
|
||||
|
Reference in New Issue
Block a user