Getting Console output from a script.



  • Hello

    I am struggling getting output from the console.

    @ QProcess OProcess;
    QString Command = "grunt > /tmp/lolx.txt";

    QDir::setCurrent(ui->plainTxtBrowserFolder->toPlainText() + "/");
    OProcess.start(Command);
    
    QString ab =        OProcess.readAll();
    

    ui->txtBrowserTerminal->append(ab);

    QString StdOutx     =   OProcess.readAllStandardOutput();  //Reads standard output
    QString StdErrorx    =   OProcess.readAllStandardError();   //Reads standard error@
    

    When I run the command "ls" or something like that everything is working perfectly.

    But when running the "Grunt" command I do not seem to get any output :/ can anyone explain me why ?

    I am sure I am in the right folder, and when I run the command from a terminal it works.

    Grunt = gruntjs.com/getting-started

    Thanks
    kind regards


  • Moderators

    welcome to devnet

    From your code snippet it looks like you read before the process has been finished. Check out "waitForFinished":http://qt-project.org/doc/qt-5/qprocess.html#waitForFinished



  • Hello,

    Thanks, well I have tried that aswell
    @ QProcess OProcess;
    QString Command = "grunt > /tmp/lolx.txt";

    QDir::setCurrent(ui->plainTxtBrowserFolder->toPlainText() + "/");
    OProcess.start(Command);
    OProcess.waitForFinished(-1);
    
    QString StdOut      =   OProcess.readAllStandardOutput();  //Reads standard output
    QString StdError    =   OProcess.readAllStandardError();   //Reads standard error
     QString a =        OProcess.readAll();
    
    ui->txtBrowserTerminal->append(a);
    ui->txtBrowserTerminal->append(StdOut);
    ui->txtBrowserTerminal->append(StdError);@
    

    But nothing comes out, when I run the command ,after I run this process , in my terminal I see the result in my terminal but nothing in my txtBrowserTerminal.


  • Lifetime Qt Champion

    Hi,

    You are redirecting the output of grunt in a file, so (unless I'm mistaken) you should not have anything on stdout only on stderr.

    You should try to run grunt without any redirection to catch its output with QProcess.

    Hope it helps



  • Hello,

    Well I tried that aswell :/ was just trying to see if the file gets created but that's not the case aswell.

    So I am guessing he doesn't call it .. or can't call it.

    Can I debug this ?

    Thanks


  • Lifetime Qt Champion

    Where is grunt located ?

    Check what QProcess::error() returns



  • It returns no such file or directory.

    But then when I try:
    @ QProcess OProcess;
    QString Command = "/usr/local/bin/grunt";

    QDir::setCurrent(ui->plainTxtBrowserFolder->toPlainText() + "/");
    OProcess.start(Command);
    OProcess.waitForFinished(-1);
    
    QString error = OProcess.errorString();
    ui->txtBrowserTerminal->append(error);
    

    @

    It returns " unknown error" and "env: node: No such file or directory"

    So now he doesn't find "node".

    I think the problem is that this QProcess doesn't get my PATH variables ? or doesn't has access to it ?

    Thanks already man !


  • Lifetime Qt Champion

    You can set the environment of QProcess using setProcessEnvironment


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.