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. Qprocess: how to debug the full command send/used to start the process?
Forum Updated to NodeBB v4.3 + New Features

Qprocess: how to debug the full command send/used to start the process?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 1.7k Views 3 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.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by
    #1

    hi there,

    I can use something like this to launch a process:
    I would like to debug/see the full command used to launch the process.

    There is "arguments()" But this gives me only the list of command options.

    proc = new QProcess();
    proc->start("/path/to/executable" , QStringList() << "option1" << "option2";
    qDebug() << "Arguments: " << proc->arguments();
    

    What I am asking is if there is a proc->showFullCommand(); tip or how to get this information.
    In the documentation I could not find something like this.

    thx in advance

    Pl45m4P 1 Reply Last reply
    0
    • ademmlerA ademmler

      @Christian-Ehrlicher

      Ok - In the terminal - from qDebug() I see everything is fine.

      I added as @Pl45m4 have said.
      qDebug() << myProcess->program() << " " << myProcess->arguments();

      Which brings this as a result:
      "pdfraster64" ("-overprint", "-overprintMode 3", "-antialias yes", "-aavector yes", "-devn", "-plateInfo", "-dpi 50", "-devnstatus /Users/ademmler/Desktop/test4C.pdf.devn", "/Users/ademmler/Desktop/test4C.pdf", "/Users/ademmler/Desktop/test4C.pdf.tiff")

      But the command (aka rip) is not started at all ...
      And there is nothing on stdout or stderr ...

      Again -how can I debug this than?

      QString program = "pdfraster64";
      QStringList arguments;
             arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);
      
         myProcess = new QProcess(this);
         myProcess->start(program, arguments);
         qDebug() << myProcess->program() << " " << myProcess->arguments();
      
      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

      arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);

      One issue here: the values of the option and their name if separated by a space shale be different items in the list. For example:

      << "-aavector" << "yes"
      

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

      ademmlerA 2 Replies Last reply
      2
      • ademmlerA ademmler

        hi there,

        I can use something like this to launch a process:
        I would like to debug/see the full command used to launch the process.

        There is "arguments()" But this gives me only the list of command options.

        proc = new QProcess();
        proc->start("/path/to/executable" , QStringList() << "option1" << "option2";
        qDebug() << "Arguments: " << proc->arguments();
        

        What I am asking is if there is a proc->showFullCommand(); tip or how to get this information.
        In the documentation I could not find something like this.

        thx in advance

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #2

        @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

        I would like to debug/see the full command used to launch the process.

        Hi,

        qDebug() << proc->program << " " << proc->arguments();

        returns

        "/path/to/executable" ("option1", "option2")
        

        And if you parse the QStringList with your args, you could create an output like the "real" command would look like.
        Something like:

        /path/to/executable -option1 -option2
        

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        ademmlerA 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

          I would like to debug/see the full command used to launch the process.

          Hi,

          qDebug() << proc->program << " " << proc->arguments();

          returns

          "/path/to/executable" ("option1", "option2")
          

          And if you parse the QStringList with your args, you could create an output like the "real" command would look like.
          Something like:

          /path/to/executable -option1 -option2
          
          ademmlerA Offline
          ademmlerA Offline
          ademmler
          wrote on last edited by ademmler
          #3

          @Pl45m4 thx for the nice approach. But this is still a guess.
          I have doubts that Process creates the proper command in my case.
          Hence I want to see what is fired up there ...

          Maybe somebody can point me to the right spot in the debugger ...

          I am aware, that this peace of code is neither "not perfect QT" nor my real application.
          It is a sketch to test and simulate my issue in a minimal version.

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          
          using namespace std;
          
          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          
          void MainWindow::on_startButton_released()
          {
          
              /* clear text report */
              ui->textEdit->clear();
          
              QString fileName = QFileDialog::getOpenFileName(this,
                                                              tr("Open Input Image"),
                                                              "~",
                                                              tr("Open file") + " (*.jpg *.jpeg *.tif *.tiff *.pdf)");
              QFile fi(fileName);
          
              if(fi.exists()) {
                  slotDoPdfRaster(fileName);  // I know I should use a connect / emit here!
              } else {
                  qDebug() << "No file opend";
              }
          
          
          }
          
          
          void MainWindow::slotDoPdfRaster(QString input) {
          
              QString inputFile = input;
              QString outputFile = input + ".tiff";
              QString report = input + ".devn";
              QDir rep;
              QDir in;
              QDir out;
          
              int ripResolutionLow = 50;
          
              ui->statusbar->showMessage("Start rip ...", 3);
          
              QString program = "pdfraster64";
              QStringList arguments;
                  arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);
          
              myProcess = new QProcess(this);
              qDebug() << "Rip program: " + program;
              qDebug() << "Rip arguments: " + arguments.join(" ");
          
              myProcess->start(program, arguments);
          
              /* show output */
              connect(myProcess, SIGNAL(readyReadStandardOutput()),this, SLOT(rightMessage()) );
              connect(myProcess, SIGNAL(readyReadStandardError()), this, SLOT(wrongMessage()) );
          
              ui->statusbar->showMessage("Idle ...", 0);
          }
          
          // show right message
          void MainWindow::rightMessage()
          {
              QByteArray strdata = myProcess->readAllStandardOutput();
              ui->textEdit->setTextColor(Qt::black);
              ui->textEdit->append(strdata);
          }
          
          // show wrong message
          void MainWindow::wrongMessage()
          {
              QByteArray strdata = myProcess->readAllStandardError();
              ui->textEdit->setTextColor(Qt::red);
              ui->textEdit->append(strdata);
          }
          
          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

            I have doubts that Process creates the proper command in my case.

            What the debug output from @Pl45m4 show you is exactly what the process gets.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            ademmlerA 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

              I have doubts that Process creates the proper command in my case.

              What the debug output from @Pl45m4 show you is exactly what the process gets.

              ademmlerA Offline
              ademmlerA Offline
              ademmler
              wrote on last edited by ademmler
              #5

              @Christian-Ehrlicher

              Ok - In the terminal - from qDebug() I see everything is fine.

              I added as @Pl45m4 have said.
              qDebug() << myProcess->program() << " " << myProcess->arguments();

              Which brings this as a result:
              "pdfraster64" ("-overprint", "-overprintMode 3", "-antialias yes", "-aavector yes", "-devn", "-plateInfo", "-dpi 50", "-devnstatus /Users/ademmler/Desktop/test4C.pdf.devn", "/Users/ademmler/Desktop/test4C.pdf", "/Users/ademmler/Desktop/test4C.pdf.tiff")

              But the command (aka rip) is not started at all ...
              And there is nothing on stdout or stderr ...

              Again -how can I debug this than?

              QString program = "pdfraster64";
              QStringList arguments;
                     arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);
              
                 myProcess = new QProcess(this);
                 myProcess->start(program, arguments);
                 qDebug() << myProcess->program() << " " << myProcess->arguments();
              
              SGaistS 1 Reply Last reply
              0
              • ademmlerA ademmler

                @Christian-Ehrlicher

                Ok - In the terminal - from qDebug() I see everything is fine.

                I added as @Pl45m4 have said.
                qDebug() << myProcess->program() << " " << myProcess->arguments();

                Which brings this as a result:
                "pdfraster64" ("-overprint", "-overprintMode 3", "-antialias yes", "-aavector yes", "-devn", "-plateInfo", "-dpi 50", "-devnstatus /Users/ademmler/Desktop/test4C.pdf.devn", "/Users/ademmler/Desktop/test4C.pdf", "/Users/ademmler/Desktop/test4C.pdf.tiff")

                But the command (aka rip) is not started at all ...
                And there is nothing on stdout or stderr ...

                Again -how can I debug this than?

                QString program = "pdfraster64";
                QStringList arguments;
                       arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);
                
                   myProcess = new QProcess(this);
                   myProcess->start(program, arguments);
                   qDebug() << myProcess->program() << " " << myProcess->arguments();
                
                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

                arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);

                One issue here: the values of the option and their name if separated by a space shale be different items in the list. For example:

                << "-aavector" << "yes"
                

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

                ademmlerA 2 Replies Last reply
                2
                • SGaistS SGaist

                  @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

                  arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);

                  One issue here: the values of the option and their name if separated by a space shale be different items in the list. For example:

                  << "-aavector" << "yes"
                  
                  ademmlerA Offline
                  ademmlerA Offline
                  ademmler
                  wrote on last edited by
                  #7

                  @SGaist thx for pointing this out. That was the missing part.
                  Hence "all kind of spaces" are handled by Process - right?

                  What is your recommendation how to create such long/complex list of arguments?
                  Can I write it like this - or is there a better way of doing?

                  arguments << "-overprint" << "-overprintMode 3"
                  << "-antialias" << yes"
                  << "-aavector yes"
                  << "-devn" << "-plateInfo"
                  << "-dpi " + QString::number(ripResolutionLow)
                  << "-devnstatus " + rep.toNativeSeparators(report)
                  << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    If I have long list of that kind of stuff, I put each entry on its own line.

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

                    ademmlerA 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      If I have long list of that kind of stuff, I put each entry on its own line.

                      ademmlerA Offline
                      ademmlerA Offline
                      ademmler
                      wrote on last edited by ademmler
                      #9

                      @SGaist thx - You mean - as I wrote it above.

                      There is comandline tools which syntax uses "="
                      like this: executable -option1 -option2=3
                      or even this: executable -option1 -option2 = 3

                      This would lead into: arguments << "-option1" << "-option2=" << "3";
                      Or into arguments << "-option1" << "-option2" << "=" << "3";

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        @ademmler said in Qprocess: how to debug the full command send/used to start the process?:

                        arguments << "-overprint" << "-overprintMode 3" << "-antialias yes" << "-aavector yes" << "-devn" << "-plateInfo" << "-dpi " + QString::number(ripResolutionLow) << "-devnstatus " + rep.toNativeSeparators(report) << in.toNativeSeparators(inputFile) << out.toNativeSeparators(outputFile);

                        One issue here: the values of the option and their name if separated by a space shale be different items in the list. For example:

                        << "-aavector" << "yes"
                        
                        ademmlerA Offline
                        ademmlerA Offline
                        ademmler
                        wrote on last edited by ademmler
                        #10

                        @SGaist

                        I am so sorry - I marked the wrong answer as the correct one.
                        Does this Forum allow me to change this? I don't find the button for this ...

                        I Marked @SGaist answer as solution, because this made everything work.
                        I think it ia so important to understand that options and values need to be in separate quotes!
                        Bevor I could never get a Process running ... maybe a good note for the documentation.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          You can mark your thread as unsolved (done) and select a new answer.

                          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