diff --git a/src/plugins/remotelinux/filesystemaccess_test.cpp b/src/plugins/remotelinux/filesystemaccess_test.cpp index 13e46619ff3..edcb8d4d01c 100644 --- a/src/plugins/remotelinux/filesystemaccess_test.cpp +++ b/src/plugins/remotelinux/filesystemaccess_test.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -181,6 +182,21 @@ void FileSystemAccessTest::testCreateRemoteFile() QVERIFY(!testFilePath.exists()); } +void FileSystemAccessTest::testWorkingDirectory() +{ + const FilePath dir = baseFilePath() / "testdir with space and 'various' \"quotes\" here"; + QVERIFY(dir.ensureWritableDir()); + QtcProcess proc; + proc.setCommand({"pwd", {}}); + proc.setWorkingDirectory(dir); + proc.start(); + QVERIFY(proc.waitForFinished()); + const QString out = proc.readAllStandardOutput().trimmed(); + QCOMPARE(out, dir.path()); + const QString err = proc.readAllStandardOutput(); + QVERIFY(err.isEmpty()); +} + void FileSystemAccessTest::testDirStatus() { FilePath filePath = baseFilePath(); diff --git a/src/plugins/remotelinux/filesystemaccess_test.h b/src/plugins/remotelinux/filesystemaccess_test.h index 84321db6ce8..087eabbcad9 100644 --- a/src/plugins/remotelinux/filesystemaccess_test.h +++ b/src/plugins/remotelinux/filesystemaccess_test.h @@ -24,6 +24,7 @@ private slots: void testCreateRemoteFile_data(); void testCreateRemoteFile(); + void testWorkingDirectory(); void testDirStatus(); void testBytesAvailable(); void testFileActions(); diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 97b6412e6c2..583a6bdeaf5 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -612,13 +612,17 @@ void SshProcessInterfacePrivate::start() cmd.addArg("-tt"); const CommandLine full = q->m_setup.m_commandLine; - if (!full.isEmpty()) { + if (!full.isEmpty()) { // Empty is ok in case of opening a terminal. + CommandLine inner; + const QString wd = q->m_setup.m_workingDirectory.path(); + if (!wd.isEmpty()) + inner.addCommandLineWithAnd({"cd", {wd}}); if (!useTerminal) { - // Empty is ok in case of opening a terminal. - cmd.addArgs(QString("echo ") + s_pidMarker + "\\$\\$" + s_pidMarker + " \\&\\& ", - CommandLine::Raw); + const QString pidArg = QString("%1\\$\\$%1").arg(QString::fromLatin1(s_pidMarker)); + inner.addCommandLineWithAnd({"echo", pidArg, CommandLine::Raw}); } - cmd.addCommandLineAsArgs(full, CommandLine::Raw); + inner.addCommandLineWithAnd(full); + cmd.addCommandLineAsSingleArg(inner); } m_process.setProcessImpl(q->m_setup.m_processImpl);