QProcess can't write commands to program

226 views Asked by At

So I want to open stockfish with a QProcess and write the command isready, to which stockfish replies readyok. I tried exactly the same commands in the terminal, where it works fine. When I try to do it in QProcess however, it only reads the opening line "Stockfish 100521 by the Stockfish developers (see AUTHORS file)" when stockfish opens. It does not reply with "readyok" after my command.

Am I writing my commands out wrong or are my wait commands wrong? I'm sorry if this question is badly structured or supported as I am new to this.

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;
1

There are 1 answers

1
SajadBlog On

you need to wait for fire this signals void readyReadStandardError() void readyReadStandardOutput() and after their read from standard error or output buffer.