Commit 72e083b4 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

fix xterm call incl. shell escaping

parent fa435213
...@@ -46,29 +46,36 @@ ConsoleProcess::~ConsoleProcess() ...@@ -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) bool ConsoleProcess::start(const QString &program, const QStringList &args)
{ {
if (m_process->state() != QProcess::NotRunning) if (m_process->state() != QProcess::NotRunning)
return false; return false;
QString shellArgs; QString shellArgs;
shellArgs += QLatin1String("cd "); shellArgs += QLatin1String("cd ");
shellArgs += workingDirectory(); shellArgs += shellEscape(workingDirectory());
shellArgs += QLatin1Char(';'); shellArgs += QLatin1Char(';');
shellArgs += program; shellArgs += shellEscape(program);
foreach (const QString &arg, args) { foreach (const QString &arg, args) {
shellArgs += QLatin1Char(' '); shellArgs += QLatin1Char(' ');
shellArgs += QLatin1Char('\''); shellArgs += shellEscape(arg);
shellArgs += arg;
shellArgs += QLatin1Char('\'');
} }
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()); m_process->setEnvironment(environment());
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(processFinished(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()) if (!m_process->waitForStarted())
return false; return false;
emit processStarted(); emit processStarted();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment