How to open console window via QProcess?
-
wrote on 31 May 2018, 11:10 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");
-
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.
-
wrote on 1 Jun 2018, 01:18 last edited by Kien Bui 6 Jan 2018, 01:25
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 -
wrote on 1 Jun 2018, 03:53 last edited by
I found a keyword: "CREATE_NEW_CONSOLE" but I don't know to use it
-
Lifetime Qt Championwrote on 1 Jun 2018, 13:38 last edited by mrjj 6 Feb 2018, 07:57
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.
-
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.
-
@JonB
Oh, thx. i missed that little word.
No idea how to get interactive shell on phone.
if even allowed. -
wrote on 2 Feb 2022, 23:37 last edited by mnbv 2 Feb 2022, 23:42
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.