0

所以我想用QProcess打开stockfish并编写命令isready,stockfish回复readyok。我在终端中尝试了完全相同的命令,它工作正常。但是,当我尝试在 QProcess 中执行此操作时,它只会在 stockfish 打开时读取开头行“Stockfish 开发人员的 Stockfish 100521(请参阅 AUTHORS 文件)”。在我发出命令后,它没有回复“readyok”。

我写错了我的命令还是我的等待命令错了?如果这个问题的结构或支持不正确,我很抱歉,因为我是新手。

QProcess OProcess;
QString Command;    //Contains the command to be executed
QStringList args;   //Contains arguments of the command

Command = "path/Stockfish/src/stockfish";
args<<"";

OProcess.start(Command,args,QIODevice::ReadWrite); //Starts execution of command
OProcess.waitForFinished();                       //Waits for execution to complete

QString StdOut      =   OProcess.readAllStandardOutput();  //Reads standard output
QString StdError    =   OProcess.readAllStandardError();   //Reads standard error

qDebug()<< "\n Printing the standard output..........\n";
qDebug()<< endl<<StdOut;
qDebug()<<"\n Printing the standard error..........\n";
qDebug()<<endl<<StdError;

OProcess.write("isready");
OProcess.waitForFinished();  //Waits for execution to complete

OProcess.waitForReadyRead();

 StdOut      =   OProcess.readAllStandardOutput();  //Reads standard output
 StdError    =   OProcess.readAllStandardError();   //Reads standard error

        qDebug()<< "\n Printing the standard output:\n";
        qDebug()<< endl<<StdOut;
        qDebug()<<"\n Printing the standard error:\n";
        qDebug()<<endl<<StdError;
return 0;
4

1 回答 1

0

您需要等待触发此信号 void readyReadStandardError() void readyReadStandardOutput() 并在从标准错误或输出缓冲区读取它们之后。

于 2021-05-19T04:20:11.500 回答