'Calling a .bat file from C program fails but if double click it works
I have this file.bat :
cd "C:\Program Files(x86)\Anydesk" && anydesk.exe
If i double click on it it works fine and does what i want.
Now i try to launch this bat file inside of my C program :
system("path\\file.bat");
But it does nothing. I see a super fast cmd opening and nothing else. I am wondering maybe it is failing because it is calling another application? But i am not sure.
How to make this work?
Solution 1:[1]
.bat is not an executable. It is a script which is processed by cmd.com.
So you need to execute it, with your .bat as a parameter:
system("cmd /C path\\script.bat");
The /C key will tell your cmd, to execute the bat and exit, once the bat is finished. You can use /K for debug purposes (execute and remain open after completion).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | White Owl |
