Discussion:
[Development] QProcess doesn't run cmd.exe
Jed Evnull
2018-12-08 04:12:59 UTC
Permalink
I'm attempting to open a cmd.exe console in Windows using Qt 5.11x. The
code fragment below works reliably for Windows 10 and Windows 8x. However,
for Windows 7 what appears to be a console window just blinks and goes
away. I've tried modifying the argument to just call cmd.exe (no .bat file)
and also included the full path to cmd.exe, neither change mattered.

QProcess p;
p.setProgram("cmd.exe");
p.setArguments({"/k", QDir::currentPath()+"/cpath.bat"});
p.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments*args) {
args->flags &= ~CREATE_NO_WINDOW;
});
p.startDetached();

I've asked this question elsewhere and have gotten no responses. Please help!
Henry Skoglund
2018-12-08 12:47:40 UTC
Permalink
Post by Jed Evnull
I'm attempting to open a cmd.exe console in Windows using Qt 5.11x. The
code fragment below works reliably for Windows 10 and Windows 8x.
However, for Windows 7 what appears to be a console window just blinks
and goes away. I've tried modifying the argument to just call cmd.exe
(no .bat file) and also included the full path to cmd.exe, neither
change mattered.
|QProcessp;p.setProgram("cmd.exe");p.setArguments({"/k",QDir::currentPath()+"/cpath.bat"});p.setCreateProcessArgumentsModifier([](QProcess::CreateProcessArguments*args){args->flags
&=~CREATE_NO_WINDOW;});p.startDetached();|
|I've asked this question elsewhere and have gotten no responses. Please
help!|
Hi, QProcess I think uses CreateProcess on Windows and that API has
stayed the same since at least Windows XP, so Windows 7 should behave
the same as versions 8 or 10.

Perhaps the anti-virus program on your Windows 7 dislikes launching
cmd.exe, try disabling it. Also, try creating a new, vanilla Qt Console
Application in Qt Creator and see if that runs.

Rgrds Henry
Mark Gaiser
2018-12-08 13:37:57 UTC
Permalink
Post by Jed Evnull
I'm attempting to open a cmd.exe console in Windows using Qt 5.11x. The
code fragment below works reliably for Windows 10 and Windows 8x. However,
for Windows 7 what appears to be a console window just blinks and goes
away. I've tried modifying the argument to just call cmd.exe (no .bat file)
and also included the full path to cmd.exe, neither change mattered.
QProcess p;
p.setProgram("cmd.exe");
p.setArguments({"/k", QDir::currentPath()+"/cpath.bat"});
p.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments*args) {
args->flags &= ~CREATE_NO_WINDOW;
});
p.startDetached();
I've asked this question elsewhere and have gotten no responses. Please help!
_______________________________________________
Development mailing list
https://lists.qt-project.org/listinfo/development
So your cmd runs, as you said it blinks for a moment.
The problem is probably in your bat file.

Could you:
1. Verify that the bat file that's in your arguments exists at all?
2. That there are no spaces in your batch file path? And if there are, that
your argument properly either escapes it or puts the whole path in quotes.
3. That the bat file runs when you call it manually on your command line
with the same line that your "QDir::currentPath()+"/cpath.bat"" evaluates
to.

Loading...