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. Opening command shell when starting a Qprocess
QtWS25 Last Chance

Opening command shell when starting a Qprocess

Scheduled Pinned Locked Moved Solved General and Desktop
c++qprocesscommand lineexe
5 Posts 3 Posters 971 Views
  • 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.
  • J Offline
    J Offline
    JCSB
    wrote on last edited by
    #1

    Hi,
    I have made a .exe file that I normally run on Windows command line, and I want to run it from my Qt GUI. I think I manage to run it, but I am not sure as there is no window popping up. I would love to have a command line window appearing and all the couts printed on it when I launch my Qprocess.. hopefully this is possible?

    Here is how I setup a path to the exe file I want to run, and how I start a qprocess from it afterwards (with a choose path button, and a lauch exe button):

    void MainWindow::on_jackExe_path_pushButton_clicked()
    {
        _exePath = QFileDialog::getOpenFileName();
        ui->jackExe_path_label->setText(_exePath);
    
    
    void MainWindow::on_json_launch_pushButton_clicked()
    {
        if(_exePath != "")
        {
            for(int i = 0; i < _testQueue.size(); i++)
            {
                QStringList arguments;
                arguments <<  "-json" << _testQueue[0].GetFileName();
                arguments <<  "-port" << ui->comPort_comboBox->currentText();
                arguments << "-help";
                qDebug() << arguments;
                _exeProcess->QProcess::start(_exePath, arguments);
                //I can't see any window! but no error message from Qt
                _testQueue.removeAt(0);
                RefreshJsonListWidget();
            }
        }
        else
        {
            qDebug() << "No Path selected!";
            QMessageBox::critical(this, tr("Error"), tr("No path chosen for Jacky.exe"));
        }
    }
    

    How can I open a shell window that runs the Jacky.exe file? Thanks a lot!

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

      Hi and welcome to devnet,

      Unless your command line application explicitly creates a new command line window, this won't happen.

      However, QProcess provides everything your need to read the output generated by your command. For example, QProcess::readyReadStandardOutput that lets you know there's something to read.

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

      J 1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        First you loop does not work at all:

        for(int i = 0; i < _testQueue.size(); i++) {
         .. 
        _testQueue.removeAt(0);
        }
        

        Only half of your elements are taken.

        Second you have to wait until the process is finished until starting it again. And no you should not use QProcess::waitForFinished() but signals and slots.

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

        J 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          First you loop does not work at all:

          for(int i = 0; i < _testQueue.size(); i++) {
           .. 
          _testQueue.removeAt(0);
          }
          

          Only half of your elements are taken.

          Second you have to wait until the process is finished until starting it again. And no you should not use QProcess::waitForFinished() but signals and slots.

          J Offline
          J Offline
          JCSB
          wrote on last edited by
          #3

          @Christian-Ehrlicher Thanks! I have removed the loop for now like so:

          void MainWindow::on_json_launch_pushButton_clicked()
          {
              if(_exePath != "")
              {
          //        for(int i = 0; i < _testQueue.size(); i++)
          //        {
                      QStringList arguments;
                      arguments <<  "-json" << _testQueue[0].GetFileName();
                      arguments <<  "-port" << ui->comPort_comboBox->currentText();
                      arguments << "-help";
                      qDebug() << arguments;
                      _exeProcess->QProcess::start(_exePath, arguments);
                      _testQueue.removeAt(0);
                      RefreshJsonListWidget();
          //        }
              }
              else
              {
                  qDebug() << "No Path selected!";
                  QMessageBox::critical(this, tr("Error"), tr("No path chosen for Jacky.exe"));
              }
          }
          

          as I would like to focus on the command line window problem. I tried running it without the loop, just to see if it would appear if I called a single file, but it doesn't

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

            Hi and welcome to devnet,

            Unless your command line application explicitly creates a new command line window, this won't happen.

            However, QProcess provides everything your need to read the output generated by your command. For example, QProcess::readyReadStandardOutput that lets you know there's something to read.

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

            J 1 Reply Last reply
            3
            • SGaistS SGaist

              Hi and welcome to devnet,

              Unless your command line application explicitly creates a new command line window, this won't happen.

              However, QProcess provides everything your need to read the output generated by your command. For example, QProcess::readyReadStandardOutput that lets you know there's something to read.

              J Offline
              J Offline
              JCSB
              wrote on last edited by
              #5

              @SGaist Thank you, this has solved my issue!! :D

              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