Home > Software design >  double quotes problems in Qstring
double quotes problems in Qstring

Time:05-30

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

CodePudding user response:

The problem is you cannot run pipes with QProcess, but only a single process. The workaround would be to pass your command as an argument to cmd.exe:

QProcess p;
p.start("cmd.exe", QStringList() << "/C" << "tasklist /FI \"IMAGENAME x32dbg.exe\" /FO LIST | findstr \"PID:\"");

CodePudding user response:

QDebug's quoting option enabled by default, so use noquote().

  • Related