Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How I can run a terminal command from a window application?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 2.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andreagenor
    wrote on last edited by andreagenor
    #1

    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);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreagenor
        wrote on last edited by
        #3

        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);
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreagenor
            wrote on last edited by
            #5

            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
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreagenor
                wrote on last edited by andreagenor
                #7

                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); 
                };
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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 :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved