How to open console window via QProcess?
-
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.
-
Hi,
What you want is called a interactive shell/prompt
This is sample for WindowsQDetachableProcess 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.
-
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 withQProcess
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.