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 can launch programs but not python (command line)
Forum Updated to NodeBB v4.3 + New Features

QProcess can launch programs but not python (command line)

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 2.7k 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.
  • J Offline
    J Offline
    jonasqt
    wrote on last edited by koahnig
    #1

    The following code is failing to launch the python command line.

    QProcess *myProcess = new QProcess(this);
    myProcess->start("\"C:\\Program Files\\Python27\\python.exe\"");
    

    If I replace python27 with (for example)

    myProcess->start("\"C:\\Program Files\\Notepad++\\notepad++.exe\"")
    

    notepad opens. Why is my program able to launch notepad but not Python Command Line?

    I tried using startDetached() but that didn't make a difference.

    QProcess::Error() gives me error 5: unknown error.

    [edit koahnig: code tags added]

    K 1 Reply Last reply
    0
    • J jonasqt

      The following code is failing to launch the python command line.

      QProcess *myProcess = new QProcess(this);
      myProcess->start("\"C:\\Program Files\\Python27\\python.exe\"");
      

      If I replace python27 with (for example)

      myProcess->start("\"C:\\Program Files\\Notepad++\\notepad++.exe\"")
      

      notepad opens. Why is my program able to launch notepad but not Python Command Line?

      I tried using startDetached() but that didn't make a difference.

      QProcess::Error() gives me error 5: unknown error.

      [edit koahnig: code tags added]

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @jonasqt

      You should use codetags (right button above the input pane) for all your code snippets. Otherwise your code lines are hard to read.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        what does qDebug() << QFile::exists("\"C:\\Program Files\\Python27\\python.exe\""); print? (I'm not taking the piss, I promise)

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        J 2 Replies Last reply
        0
        • VRoninV VRonin

          what does qDebug() << QFile::exists("\"C:\\Program Files\\Python27\\python.exe\""); print? (I'm not taking the piss, I promise)

          J Offline
          J Offline
          jonasqt
          wrote on last edited by
          #4

          @VRonin it prints false. so that means that my the python.exe file doesn't exist, correct? Is there another explanation for this other than that I might have errors in my filepath? Because I cant see where it could be wrong.

          1 Reply Last reply
          0
          • VRoninV VRonin

            what does qDebug() << QFile::exists("\"C:\\Program Files\\Python27\\python.exe\""); print? (I'm not taking the piss, I promise)

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

            @VRonin I maneged to fix it so that qDebug << exists() now returns true. Python is still not launching though.

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

              Hi,

              What are you expecting when calling python like that ?

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

              J 2 Replies Last reply
              0
              • SGaistS SGaist

                Hi,

                What are you expecting when calling python like that ?

                J Offline
                J Offline
                jonasqt
                wrote on last edited by
                #7

                @SGaist I'm expecting the python command line to launch.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  What are you expecting when calling python like that ?

                  J Offline
                  J Offline
                  jonasqt
                  wrote on last edited by
                  #8

                  @SGaist is it wrong to expect the command line to actually open as a window? I've just noticed that I can open most applications except command lines. (When I try to launch cmd.exe, git-cmd.exe, python.exe nothing happens while I can open e.g. chrome.exe, git-bash.exe, notepad.exe)

                  jsulmJ 1 Reply Last reply
                  0
                  • J jonasqt

                    @SGaist is it wrong to expect the command line to actually open as a window? I've just noticed that I can open most applications except command lines. (When I try to launch cmd.exe, git-cmd.exe, python.exe nothing happens while I can open e.g. chrome.exe, git-bash.exe, notepad.exe)

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #9

                    @jonasqt said in QProcess can launch programs but not python (command line):

                    is it wrong to expect the command line to actually open as a window

                    Yes, it is. Command line tools do not have any windows - they run in a shell/terminal (terminal has a window). On Windows you can try pythonw.exe instead of python.exe. Or you start cmd.exe and pass the path to Python executable with -c as parameter to cmd.exe

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2

                    • Login

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