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. Running external Python 3 script

Running external Python 3 script

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 640 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.
  • S Offline
    S Offline
    Saltywaffles
    wrote on 5 Sept 2019, 21:22 last edited by
    #1

    I want to run an external .py script that I made. I have tested the script in VS and it runs fine. When I try to implement it in QT, it will not open. Here is what I have in my .cpp file:

    QString path = "C:/../python.exe";
    QString  command("python");
    QStringList params = QStringList() << "C:/../test.py";
    
    QProcess *process = new QProcess();
    process->startDetached(command, params, path);
    process->waitForFinished();
    process->close();
    

    I do not get any errors when pressing the button, in fact, I get nothing from the output. Any ideas?

    J A 2 Replies Last reply 5 Sept 2019, 21:30
    0
    • S Saltywaffles
      5 Sept 2019, 21:22

      I want to run an external .py script that I made. I have tested the script in VS and it runs fine. When I try to implement it in QT, it will not open. Here is what I have in my .cpp file:

      QString path = "C:/../python.exe";
      QString  command("python");
      QStringList params = QStringList() << "C:/../test.py";
      
      QProcess *process = new QProcess();
      process->startDetached(command, params, path);
      process->waitForFinished();
      process->close();
      

      I do not get any errors when pressing the button, in fact, I get nothing from the output. Any ideas?

      J Online
      J Online
      JonB
      wrote on 5 Sept 2019, 21:30 last edited by
      #2

      @saltywaffles
      What do you mean by "it will not open."? "I get nothing from the output." what output? Why are you using QProcess::startDetached() to run your script? How do you know it does not run?

      1 Reply Last reply
      2
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 5 Sept 2019, 21:30 last edited by
        #3

        Hi,

        If you want know know exactly what is going on, you should not call startDetached.

        Start your QProcess normally and check the it starts correctly and for errors.

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

        S 1 Reply Last reply 5 Sept 2019, 22:02
        2
        • S SGaist
          5 Sept 2019, 21:30

          Hi,

          If you want know know exactly what is going on, you should not call startDetached.

          Start your QProcess normally and check the it starts correctly and for errors.

          S Offline
          S Offline
          Saltywaffles
          wrote on 5 Sept 2019, 22:02 last edited by
          #4

          @sgaist

          How would that look? I am a little lost figuring out the Qprocess

          J 1 Reply Last reply 7 Sept 2019, 09:14
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 6 Sept 2019, 22:13 last edited by
            #5

            You have an example in the Synchronous Process API part of QProcess's documentation.

            You have the error method.

            You should also check the communication channels. Read the content of the standard output and standard error to see what is happening.

            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
            3
            • S Saltywaffles
              5 Sept 2019, 22:02

              @sgaist

              How would that look? I am a little lost figuring out the Qprocess

              J Online
              J Online
              JonB
              wrote on 7 Sept 2019, 09:14 last edited by JonB 9 Jul 2019, 09:24
              #6

              @saltywaffles
              You will need to look at the links @SGaist has given you and implement. But first things first: have you replaced startDetached() by start(), does that behave differently for you? Or you might find the static https://doc.qt.io/qt-5/qprocess.html#execute a simpler place to start out from: its return code at least tells you what happened when invoking the process, before you proceed to pick up the output. The problem is you still have not explained what you mean by "I get nothing from the output." Does your script send output to stdout which you see when you run it elsewhere (e.g. a terminal) and you want to capture that out in your Qt program?

              1 Reply Last reply
              0
              • S Saltywaffles
                5 Sept 2019, 21:22

                I want to run an external .py script that I made. I have tested the script in VS and it runs fine. When I try to implement it in QT, it will not open. Here is what I have in my .cpp file:

                QString path = "C:/../python.exe";
                QString  command("python");
                QStringList params = QStringList() << "C:/../test.py";
                
                QProcess *process = new QProcess();
                process->startDetached(command, params, path);
                process->waitForFinished();
                process->close();
                

                I do not get any errors when pressing the button, in fact, I get nothing from the output. Any ideas?

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 7 Sept 2019, 09:53 last edited by
                #7

                @saltywaffles which Qt version are you using?

                Qt has to stay free or it will die.

                1 Reply Last reply
                0

                1/7

                5 Sept 2019, 21:22

                • Login

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