Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top