0

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

RRR
  • 3,937
  • 13
  • 51
  • 75
  • Your code that creates a QProcess looks like it operates on a local variable instead of the class member. Try with `myProcess = new QProcess`, not `QProcess* myProcess = new QProcess`. – Frank Osterfeld Aug 15 '13 at 12:05
  • its class member, I just copied it here for the example – RRR Aug 15 '13 at 12:15
  • So, your Qt program creates a QProcess which launches a .Net program. The .Net program crashes with an exception that happens to output to stdout, rather than stderr and you're blaming Qt for the .Net crash? Am I missing something? – TheDarkKnight Aug 15 '13 at 12:21
  • Apparently you are right that thsi is a .Net crash. but the crash doen't happen when I'm runnimg the exe manually - not from QT. so that I think that this should be a QT problem - no? if not what can be the issue? – RRR Aug 15 '13 at 12:45
  • what can I do to find the issue? – RRR Aug 15 '13 at 12:48
  • Try starting the process detached. Even if you need the output. It is just for debugging. Starting detached is a close to starting from commandline as possible. If it still crashes, perhaps an environment problem? Wrong workdir? – Greenflow Aug 15 '13 at 19:13
  • Program and arguments contain everything right, surely? Can you share the content of those variables? – László Papp Aug 16 '13 at 03:24

1 Answers1

1

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.

RRR
  • 3,937
  • 13
  • 51
  • 75