Qstring中的双引号问题
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:\"}
正确的文字必须是
{tasklist /FI "IMAGENAME eq x32dbg.exe" /FO LIST | findstr "PID:"}
我试过\"
并在 const char * 中添加命令行
所有 return 相同的结果
问题是您不能 运行 使用 QProcess 进行管道传输,而只能使用单个进程。解决方法是将您的命令作为参数传递给 cmd.exe:
QProcess p;
p.start("cmd.exe", QStringList() << "/C" << "tasklist /FI \"IMAGENAME x32dbg.exe\" /FO LIST | findstr \"PID:\"");
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 ;
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:\"}
正确的文字必须是
{tasklist /FI "IMAGENAME eq x32dbg.exe" /FO LIST | findstr "PID:"}
我试过\" 并在 const char * 中添加命令行 所有 return 相同的结果
问题是您不能 运行 使用 QProcess 进行管道传输,而只能使用单个进程。解决方法是将您的命令作为参数传递给 cmd.exe:
QProcess p;
p.start("cmd.exe", QStringList() << "/C" << "tasklist /FI \"IMAGENAME x32dbg.exe\" /FO LIST | findstr \"PID:\"");
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 ;