From 72e083b425e6978c8593a727447a006588de1048 Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Date: Thu, 15 Jan 2009 19:44:59 +0100
Subject: [PATCH] fix xterm call incl. shell escaping

---
 .../projectexplorer/consoleprocess_unix.cpp   | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/plugins/projectexplorer/consoleprocess_unix.cpp b/src/plugins/projectexplorer/consoleprocess_unix.cpp
index 7b432c0af03..122ae7e4bdf 100644
--- a/src/plugins/projectexplorer/consoleprocess_unix.cpp
+++ b/src/plugins/projectexplorer/consoleprocess_unix.cpp
@@ -46,29 +46,36 @@ ConsoleProcess::~ConsoleProcess()
 {
 }
 
+static QString shellEscape(const QString &in)
+{
+    QString out = in;
+    out.replace('\'', "'\''");
+    out.prepend('\'');
+    out.append('\'');
+    return out;
+}
+
 bool ConsoleProcess::start(const QString &program, const QStringList &args)
 {
     if (m_process->state() != QProcess::NotRunning)
         return false;
     QString shellArgs;
     shellArgs += QLatin1String("cd ");
-    shellArgs += workingDirectory();
+    shellArgs += shellEscape(workingDirectory());
     shellArgs += QLatin1Char(';');
-    shellArgs += program;
+    shellArgs += shellEscape(program);
     foreach (const QString &arg, args) {
         shellArgs += QLatin1Char(' ');
-        shellArgs += QLatin1Char('\'');
-        shellArgs += arg;
-        shellArgs += QLatin1Char('\'');
+        shellArgs += shellEscape(arg);
     }
-    shellArgs += QLatin1String("; echo; echo \"Press enter to close this window\"; read");
+    shellArgs += QLatin1String("; echo; echo \"Press enter to close this window\"; read DUMMY");
 
     m_process->setEnvironment(environment());
 
     connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
             this, SLOT(processFinished(int, QProcess::ExitStatus)));
 
-    m_process->start(QLatin1String("xterm"), QStringList() << QLatin1String("-e") << shellArgs);
+    m_process->start(QLatin1String("xterm"), QStringList() << QLatin1String("-e") << "/bin/sh" << "-c" << shellArgs);
     if (!m_process->waitForStarted())
         return false;
     emit processStarted();
-- 
GitLab