How to launch batch script from Qt?
-
wrote on 22 Feb 2018, 20:04 last edited by
I have several batch scripts which reside in a common folder outside the development folder my Qt app is built in.
If I move the batch files into the same folder as my exe and run
switchDevProcess->execute(".\\Switch_to_development.bat");
The batch file runs as expected. However if I try to run the batch file from where it actually will be in production
switchDevProcess->execute("C:\\epic\\GPS Scripts\\Switch_to_development.bat");
Nothing happens. What am I missing?
-
I have several batch scripts which reside in a common folder outside the development folder my Qt app is built in.
If I move the batch files into the same folder as my exe and run
switchDevProcess->execute(".\\Switch_to_development.bat");
The batch file runs as expected. However if I try to run the batch file from where it actually will be in production
switchDevProcess->execute("C:\\epic\\GPS Scripts\\Switch_to_development.bat");
Nothing happens. What am I missing?
@graniteDev said in How to launch batch script from Qt?:
switchDevProcess->execute("C:\epic\GPS Scripts\Switch_to_development.bat");
May the problem be related to the space in your path? Can you try a path without space?
PS: if switchDevProcess is a
QProcess
, you should rather use forward slashes/
instead backslashes\
as path separator. -
Hi,
To add to @aha_1980, you should check the status code and errorOccured signal from QProcess.
-
Hi
and be aware of space in path."C:\\epic\\**GPS Scripts**\\Switch_to_development.bat"
-
wrote on 22 Feb 2018, 20:26 last edited by
I can't believe the space was the problem. I had actually tried to fix that earlier using \ to escape the space, but that didn't help, so I assumed the space was not the problem.
Yes, removing the space worked. Problem is, I don't have control over that directory, I have to live with the space, and spaces in other directories. I'm building this right now, see if works...
switchDevProcess->execute("C:/epic/GPS\ Scripts/Switch_to_development.bat");
-
wrote on 22 Feb 2018, 20:31 last edited by
@mrjj
escaping the space with \ didn't work, do I need to use the double ** like you did, or was that simply to bring it to my attention? -
@mrjj
escaping the space with \ didn't work, do I need to use the double ** like you did, or was that simply to bring it to my attention?@graniteDev
The ** is just for bold but i ruined it with code tags :)
Escaping normally works. Let me check.Update:
https://forum.qt.io/topic/81087/qt-create-cmd-and-execute-bat-file/2Seems to escape the whole path. not just space.
-
wrote on 22 Feb 2018, 20:41 last edited by
So I've tried encapsulating the whole string in single quotes....
switchDevProcess->execute("'C:/epic/GPS Scripts/Switch_to_development.bat'");
...and escaping the space...
switchDevProcess->execute("C:/epic/GPS\ Scripts/Switch_to_development.bat");
neither worked. How is one supposed to deal with spaces in the path?
-
Did you try my suggestions (status code, errorOccured signal) to see what is happening ?
-
Hi
Something like"\"C:\\epic\\GPS Scripts\\Switch_to_development.bat\""
-
wrote on 22 Feb 2018, 20:48 last edited by
I get
QIODevice::read: device not open
-
wrote on 22 Feb 2018, 20:57 last edited by
@mrjj said in How to launch batch script from Qt?:
Hi
Something like"\"C:\\epic\\GPS Scripts\\Switch_to_development.bat\""
YES! This worked! Thank you!
1/12