Reputation: 4175
I am developing an application that creates and runs another Qprocess. My code is:
QProcess myProcess = new QProcess();
connect(myProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(sendProcessCompleted(int,QProcess::ExitStatus)));
connect(myProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(sendProcessError(QProcess::ProcessError)));
myProcess->start(program, arguments);
void SensorSimulator::sendProcessCompleted(int exitError, QProcess::ExitStatus exitStatus)
{
if(exitStatus == QProcess::CrashExit)
{
QString errorMessage("SensorSimulator is unexpectedly crashed.");
emit ProcessError(errorMessage);
}
else
{
QString p_stdout = myProcess->readAllStandardOutput();
QString p_stderr = myProcess->readAllStandardError();
}
}
void SensorSimulator::sendProcessError(QProcess::ProcessError error)
{
QString p_stdout = myProcess->readAllStandardOutput();
QString p_stderr = myProcess->readAllStandardError();
QString errorMessage;
errorMessage = "SensorSimulator is unexpectedly crashed. ProcessError: " + error;
//emit ProcessError(errorMessage);
}
I am getting this exception in the p_stdout:
Running, to stop press 'S' or close the window. Exception Found: Type: System.InvalidOperationException Message: Cannot see if a key has been pressed when either application does not have a console or when console input has been redirected from a file. Try Console.In.Peek.
Can anyone please help?
EDIT: the process I am running is a .Net application
Upvotes: 0
Views: 1393
Reputation: 4175
The problem was a little specific but the solution may help peoples that have the same error message to understand what it is.
The procees I ran used Console.KeyAvailable
property that according to MSDN throws exception when the input to the the process is a redirected input:
InvalidOperationException : Standard input is redirected to a file instead of the keyboard.
When I changed it to Console.In.Peek, everything works fine.
Upvotes: 1