我尝试了解有关QProcess的更多信息。我可以使用以下代码通过qt文档与cmd.exe进行交互。问题是-一切正常,直到我尝试使用参数运行相同的命令。在这种情况下,程序仅返回一些数字(62097)。有人可以告诉我-如何以正确的方式与cmd.exe通信吗?谢谢。
1。通过“写”方法进行通讯
QString program = "cmd";
QStringList arguments;
arguments << "";
QProcess *myProcess = new QProcess(this);
myProcess->start(program, arguments);
myProcess->waitForReadyRead();
qDebug()<< myProcess->readAllStandardOutput();
myProcess->write("cd C:\\\n");
myProcess->waitForBytesWritten();
myProcess->write("dir\n");
myProcess->waitForBytesWritten();
myProcess->waitForReadyRead();
qDebug()<< myProcess->readAllStandardOutput();
myProcess->close();
qDebug() << myProcess->exitCode();
2。使用参数进行通讯(无效)
QString program = "cmd";
QStringList arguments;
arguments << "dir";
QProcess *myProcess = new QProcess(this);
myProcess->start(program, arguments);
myProcess->waitForReadyRead();
qDebug()<< myProcess->readAllStandardOutput();
myProcess->close();
qDebug() << myProcess->exitCode();