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. Start script in QProcess?
Forum Updated to NodeBB v4.3 + New Features

Start script in QProcess?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 1.1k Views 1 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by
    #1

    Hi!
    I have script:

    cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py
    

    How I can start this script in QProcess?
    This not work:

    m_process.start("cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py")
    
    JonBJ 1 Reply Last reply
    0
    • M Mihaill

      Hi!
      I have script:

      cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py
      

      How I can start this script in QProcess?
      This not work:

      m_process.start("cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py")
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Mihaill

      m_process.start("cmd", [ "/c", "cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py" ])
      

      Or

      m_process.setWorkingDirectory("C:/PythonProjects/MibToJson")
      m_process.start("python", ["C:/PythonProjects/MibToJson/mibToJson.py"])
      
      M 1 Reply Last reply
      1
      • JonBJ JonB

        @Mihaill

        m_process.start("cmd", [ "/c", "cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py" ])
        

        Or

        m_process.setWorkingDirectory("C:/PythonProjects/MibToJson")
        m_process.start("python", ["C:/PythonProjects/MibToJson/mibToJson.py"])
        
        M Offline
        M Offline
        Mihaill
        wrote on last edited by Mihaill
        #3

        @JonB If I do this

        m_process.execute("cmd",  { "/c", "python C:/PythonProjects/MibToJson/mibToJson.py"} );
        

        Then I get error:

        Python was not found
        

        But in console cmd this script worked.
        And if doing this:

        m_process.start("python", {"C:/PythonProjects/MibToJson/mibToJson.py"});
        

        Then ,y code in script not creadet file.

        jsulmJ 1 Reply Last reply
        0
        • M Mihaill

          @JonB If I do this

          m_process.execute("cmd",  { "/c", "python C:/PythonProjects/MibToJson/mibToJson.py"} );
          

          Then I get error:

          Python was not found
          

          But in console cmd this script worked.
          And if doing this:

          m_process.start("python", {"C:/PythonProjects/MibToJson/mibToJson.py"});
          

          Then ,y code in script not creadet file.

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

          @Mihaill said in Start script in QProcess?:

          Python was not found

          Then use absolute path to python.exe ...

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

          M 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Mihaill said in Start script in QProcess?:

            Python was not found

            Then use absolute path to python.exe ...

            M Offline
            M Offline
            Mihaill
            wrote on last edited by
            #5

            @jsulm I use absolute path, but it not help me

            jsulmJ 1 Reply Last reply
            0
            • M Mihaill

              @jsulm I use absolute path, but it not help me

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

              @Mihaill said in Start script in QProcess?:

              but it not help me

              And what is the problem now?

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

              M 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Mihaill said in Start script in QProcess?:

                but it not help me

                And what is the problem now?

                M Offline
                M Offline
                Mihaill
                wrote on last edited by
                #7

                @jsulm My python script not work and not create file.
                It is to cant create file

                m_process.start("C:/PythonProjectsMibToJson/venv/Scripts/python.exe", {  "C:/PythonProjects/MibToJson/mibToJson.py"});
                
                JonBJ 1 Reply Last reply
                0
                • M Mihaill

                  @jsulm My python script not work and not create file.
                  It is to cant create file

                  m_process.start("C:/PythonProjectsMibToJson/venv/Scripts/python.exe", {  "C:/PythonProjects/MibToJson/mibToJson.py"});
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Mihaill
                  Does your python.exe accept C:/PythonProjects/MibToJson/mibToJson.py on the command line with those forward slashes? I don't know, if the python.exe runs but something goes wrong with the path passed in I would make that a native path with backslashes. (The same would also apply in your attempt with cmd /c ... earlier.)

                  Please try to think of others when phrasing your questions or answering.

                  My python script not work and not create file.

                  It is to cant create file

                  What is this about? Create what? You know that we don't know what your script might or might not do, we don't know what "doesn't work" means to you. If you know it tries to create a file from the command line argument why don't you tell us? Otherwise we have no idea what you are talking about.

                  M 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Mihaill
                    Does your python.exe accept C:/PythonProjects/MibToJson/mibToJson.py on the command line with those forward slashes? I don't know, if the python.exe runs but something goes wrong with the path passed in I would make that a native path with backslashes. (The same would also apply in your attempt with cmd /c ... earlier.)

                    Please try to think of others when phrasing your questions or answering.

                    My python script not work and not create file.

                    It is to cant create file

                    What is this about? Create what? You know that we don't know what your script might or might not do, we don't know what "doesn't work" means to you. If you know it tries to create a file from the command line argument why don't you tell us? Otherwise we have no idea what you are talking about.

                    M Offline
                    M Offline
                    Mihaill
                    wrote on last edited by
                    #9

                    @JonB I install in OS python, in cmd this work

                    python C:/PythonProjects/MibToJson/mibToJson.py
                    

                    My script mibToJson.py must create file, using absolute path. Script not need arguments.
                    And it's work in cmd, but not work in QProcess

                    jsulmJ 1 Reply Last reply
                    0
                    • M Mihaill

                      @JonB I install in OS python, in cmd this work

                      python C:/PythonProjects/MibToJson/mibToJson.py
                      

                      My script mibToJson.py must create file, using absolute path. Script not need arguments.
                      And it's work in cmd, but not work in QProcess

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

                      @Mihaill Please add error handling (should be standard in properly written applications):
                      https://doc.qt.io/qt-6/qprocess.html#errorOccurred
                      https://doc.qt.io/qt-6/qprocess.html#readAllStandardError

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

                      M 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Mihaill Please add error handling (should be standard in properly written applications):
                        https://doc.qt.io/qt-6/qprocess.html#errorOccurred
                        https://doc.qt.io/qt-6/qprocess.html#readAllStandardError

                        M Offline
                        M Offline
                        Mihaill
                        wrote on last edited by
                        #11

                        @jsulm I get error:

                        "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.\r\n"
                        
                        JonBJ jsulmJ 2 Replies Last reply
                        0
                        • M Mihaill

                          @jsulm I get error:

                          "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.\r\n"
                          
                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #12

                          @Mihaill
                          So you have your answer. Presumably whatever python.exe you have somewhere is not on your PATH.

                          And it's work in cmd, but not work in QProcess

                          Then are their PATHs different? Try specifying the full path to python executable as QProcess command.

                          1 Reply Last reply
                          0
                          • M Mihaill

                            @jsulm I get error:

                            "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.\r\n"
                            
                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @Mihaill So, is this patch actually valid: C:/PythonProjectsMibToJson/venv/Scripts/python.exe
                            What happens if you enter and execute it in cmd.exe?

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

                            M 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @Mihaill So, is this patch actually valid: C:/PythonProjectsMibToJson/venv/Scripts/python.exe
                              What happens if you enter and execute it in cmd.exe?

                              M Offline
                              M Offline
                              Mihaill
                              wrote on last edited by
                              #14

                              @jsulm I'm restart computer and it's help me.

                              1 Reply Last reply
                              0
                              • M Mihaill has marked this topic as solved on

                              • Login

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