QT - create CMD and execute .bat file
-
wrote on 7 Jul 2017, 11:01 last edited by
Hi Guys, i am new in developing with QT and i have problems by starting a .bat file, do i need to start a cmd.exe and start there my .bat file or is there an easy way to execute it. Maybe someone has an hint for me, thanks
I tried it like that:
QStringList arguments;
arguments << "/c C:/Program Files (x86)/test/test.bat ";
QProcess exec;
exec.start("C:/WINDOWS/system32/cmd.exe", arguments);
exec.waitForFinished(); -
Hi Guys, i am new in developing with QT and i have problems by starting a .bat file, do i need to start a cmd.exe and start there my .bat file or is there an easy way to execute it. Maybe someone has an hint for me, thanks
I tried it like that:
QStringList arguments;
arguments << "/c C:/Program Files (x86)/test/test.bat ";
QProcess exec;
exec.start("C:/WINDOWS/system32/cmd.exe", arguments);
exec.waitForFinished();@TryToQT said in QT - create CMD and execute .bat file:
QStringList arguments;
arguments << "/c C:/Program Files (x86)/test/test.bat ";
QProcess exec;
exec.start("C:/WINDOWS/system32/cmd.exe", arguments);should be:
QStringList arguments; arguments << "/c" << "\"C:\\Program Files (x86)\\test\\test.bat\""; QProcess exec; exec.start("cmd.exe", arguments);
-
wrote on 7 Jul 2017, 11:50 last edited by
thank you for your reply, but the .bat wasn't executed after these lines, any ideas which i can try instead
-
wrote on 7 Jul 2017, 12:25 last edited by
Hi,
why don't you check (after process fails to start) QProcess::error() method?From top of my head I would first try to not use backslash "" but just used regular slash "/" instead. It may sound silly but works under Windows and you have less characters to escape.
Secondly, you can use start() with single QString parameter that has all the parameters - worth trying that way.
And check QProcess::error() for result. -
thank you for your reply, but the .bat wasn't executed after these lines, any ideas which i can try instead
-
wrote on 30 Aug 2022, 12:33 last edited by
replace exec.start("cmd.exe", arguments); with
exec.execute("cmd.exe", arguments);