c++qtquotesqstringqprocess

double quotes problems in Qstring


QProcess p;
QString aa = "tasklist /FI 'IMAGENAME x32dbg.exe' /FO LIST | findstr 'PID:'";
aa.replace(0x27,0x22);
qInfo() << aa; 
p.start(aa.toStdString().c_str());
p.waitForFinished();
qInfo() << "Output:" << p.readAllStandardOutput() << "Error:" << p.readAllStandardError();
// returned error <ERROR: Invalid argument/option - 'x32dbg.exe\"'.\r\nType \"TASKLIST /?\" for usage.\r\n">

qebug return

{tasklist /FI \"IMAGENAME x32dbg.exe\" /FO LIST | findstr \"PID:\"}

the correct text must be

{tasklist /FI "IMAGENAME eq x32dbg.exe" /FO LIST | findstr "PID:"}

i tried with \" and add the command line in const char * all return same result


Solution

  • bool isRunning(const QString &process) {
      QProcess tasklist;
      tasklist.start(
            "tasklist",
            QStringList() << "/NH"
                          << "/FO" << "CSV"
                          << "/FI" << QString("IMAGENAME eq %1").arg(process));
      tasklist.waitForFinished();
      QString output = tasklist.readAllStandardOutput();
      qInfo() << output ;