[Development] QProcess doesn't run cmd.exe

Jed Evnull jedevnull at gmail.com
Mon Dec 10 04:46:42 CET 2018


Same issue with a test program with just a single button calling this code:

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

Please note that I removed the bat file w/o effect. Same issue, no cmd
window.

With Qt 3.6 and prior I used the code below to open a cmd window. This code
no longer works with  >= 5.10

  cstring = "cmd /k " +QDir::currentPath()+"/cpath.bat";
  QProcess::startDetached(cstring);




On Sat, Dec 8, 2018 at 8:40 AM Mark Gaiser <markg85 at gmail.com> wrote:

> On Sat, Dec 8, 2018 at 5:24 AM Jed Evnull <jedevnull at gmail.com> wrote:
>
>> 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
>> Development at lists.qt-project.org
>> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20181209/ad7675ec/attachment.html>


More information about the Development mailing list