Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to open console window via QProcess?

    General and Desktop
    5
    8
    3734
    Loading More Posts
    • 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.
    • K
      Kien Bui last edited by

      I init a QProcess to open a console window, but no window is show.

      QProcess *process = new QProcess();
      process->start("adb devices");
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        There's no reason for any console window to be shown when executing such a command.

        If you want to parse the output of your process then you can read what was sent to stdout once your command has finished.

        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 Reply Quote 3
        • K
          Kien Bui last edited by Kien Bui

          To work with Android device, I need open a console window. I want to open a console window to continue text command
          Eg: "adb -s device shell" to open shell access android device

          1 Reply Last reply Reply Quote 0
          • K
            Kien Bui last edited by

            I found a keyword: "CREATE_NEW_CONSOLE" but I don't know to use it

            1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion last edited by mrjj

              Hi,
              What you want is called a interactive shell/prompt
              This is sample for Windows

              QDetachableProcess process;
                  QString program = "cmd.exe";
                  QStringList arguments = QStringList() << "/K" << "C:\\Program Files\\Inkscape\\python.exe";
                  process.setCreateProcessArgumentsModifier(
                              [](QProcess::CreateProcessArguments *args) {
                      args->flags |= CREATE_NEW_CONSOLE;
                      args->startupInfo->dwFlags &=~ STARTF_USESTDHANDLES;
                  });
                  process.start(program, arguments);
                  process.detach();
                  }
              

              starts python and let u type commands in it.

              JonB 1 Reply Last reply Reply Quote 2
              • JonB
                JonB @mrjj last edited by

                @mrjj
                Yes, but the OP wants it for Android! :)

                mrjj 1 Reply Last reply Reply Quote 1
                • mrjj
                  mrjj Lifetime Qt Champion @JonB last edited by

                  @JonB
                  Oh, thx. i missed that little word.
                  No idea how to get interactive shell on phone.
                  if even allowed.

                  1 Reply Last reply Reply Quote 1
                  • M
                    mnbv last edited by mnbv

                    Wanted to do something similar and found this while checking if QProcess could handle it conveniently (it can't, as seen above).

                    Just use std::system. Doing it with QProcess just makes extra work. E.g. for the OP:

                    #include <cstdlib>
                    
                    std::system("adb -s device shell");
                    

                    If you want to just open a command shell, the command depends on the platform but it'd be something like:

                    std::system("cmd"); // windows
                    std::system("/bin/bash"); // linux, maybe osx? 
                    // etc...
                    

                    For that Python example above:

                    std::system("\"C:\\Program Files\\Inkscape\\python.exe\"");
                    
                    // or if necessary:
                    std::system("cmd /K \"C:\\Program Files\\Inkscape\\python.exe\"");
                    
                    // or if python is in the path, just:
                    std::system("python");
                    

                    PS This whole thread is a bit silly. The OP didn't want to open a shell on a phone, and there's definitely good reasons to start adb in a console window (it's a console-based interactive shell for debugging an attached Android device). The OP wanted to start it in a console window so they could continue to use it in said console window after starting it.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post