How I can run a terminal command from a window application?



  • Hi there,
    I use one command to process images through terminal in OSX.
    denoise [some flags] [path]

    denoise /Users/andreagenor/Desktop/testeRenderman.exr
    

    I would like to do a window application to learn and turn my job easy.

    I'm trying to do this way, but the process not starting.
    What i need to do?

        QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),"/Users/andreagenor/untitled.exr", tr("Images (*.exr *.xpm *.jpg)"));
    
        QProcess *proc = new QProcess(this);
        QStringList flags;
        flags.append(filename);
        proc->start("denoise", flags);
    
        ui->statusBar->showMessage(filename);
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should add checking about whether QProcess started correctly, that no error did happen etc.

    You should also check the content of the standard output and standard error from QProcess.



  • Hi SGaist, thank you!

    I did some changes and it appear to be running the command, but I receive this error from Renderman license.

    T44002 License file setting is not set in rendermn.ini - aborting.
    

    But it works fine from terminal.
    I did some environment variables in the ~/.bash_profile

    export RMANTREE="/Applications/Pixar/RenderManProServer-21.3"
    export RMSTREE="/Applications/Pixar/RenderManForMaya-21.3-maya2017"
    export PATH="${RMANTREE}/bin:${PATH}"
    

    If i running this command in the terminal, all works and images are read and write correctly

    /Applications/Pixar/RenderManProServer-21.3/bin/denoise /Users/andreagenor/Desktop/testeRenderman.exr
    

    Here is the last code

    void MainWindow::on_toolButton_clicked()
    {
        QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),"/Users/andreagenor/untitled.exr", tr("Images (*.exr)"));
    
        QProcess *proc = new QProcess(this);
        QStringList env = QProcess::systemEnvironment();
        proc->setEnvironment(env);
    
        QStringList flags;
        flags.append(filename);
    
        proc->startDetached("/Applications/Pixar/RenderManProServer-21.3/bin/denoise", QStringList(filename), "/");
    
        ui->statusBar->showMessage(filename);
    }
    

  • Lifetime Qt Champion

    You should setup your QProcess environment then, see QProcess::setProcessEnvironment.



  • I still can't get :(
    Someone can help me?

    void MainWindow::on_toolButton_clicked()
    {
        QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),"/Users/andreagenor/untitled.exr", tr("Images (*.exr)"));
    
        QProcess *proc = new QProcess(this);
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert("RMANTREE", "/Applications/Pixar/RenderManProServer-21.3");
        env.insert("RMSTREE", "/Applications/Pixar/RenderManForMaya-21.3-maya2017");
        env.insert("PATH", "${RMANTREE}/bin:${PATH}");
        proc->setProcessEnvironment(env);
    
        QStringList flags;
        flags.append(filename);
    
        proc->startDetached("/Applications/Pixar/RenderManProServer-21.3/bin/denoise", flags, "/");
    
        ui->statusBar->showMessage(filename);
    };
    

    The application Output is:

    Starting /Users/andreagenor/Documents/ProjetosCPP/build-RM_Denoise-Desktop_Qt_5_8_0_clang_64bit-Debug/RM_Denoise.app/Contents/MacOS/RM_Denoise...
    T44002 License file setting is not set in rendermn.ini - aborting.
    /Users/andreagenor/Documents/ProjetosCPP/build-RM_Denoise-Desktop_Qt_5_8_0_clang_64bit-Debug/RM_Denoise.app/Contents/MacOS/RM_Denoise exited with code 0
    

  • Lifetime Qt Champion

    startDetached is a static method that you are calling like a standard method, you likely even have a warning about that when compiling.

    Use start, otherwise the modifications you made the environment of proc won't be taken into account.



  • I did!
    This is the solution

    void MainWindow::on_toolButton_clicked()
    {
        QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),"/Users/andreagenor/untitled.exr", tr("Images (*.exr)"));
    
        QProcess proc;
        QString commandPath;
        QStringList flags;
    
        commandPath = "/Applications/Pixar/RenderManProServer-21.3/bin/denoise";
    
        flags.append("-f");
        flags.append("+strength0.7.filteroverride.json");
        flags.append(filename);
    
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert("RMANTREE", "/Applications/Pixar/RenderManProServer-21.3");
        env.insert("RMSTREE", "/Applications/Pixar/RenderManForMaya-21.3-maya2017");
        env.insert("PATH", "${RMANTREE}/bin:${PATH}");
        proc.setProcessEnvironment(env);
    
        proc.start(commandPath,flags,QIODevice::ReadWrite);
        proc.waitForFinished(-1); 
    };
    

  • Lifetime Qt Champion

    Great !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum members may know a solution has been found :)


Log in to reply
 

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