简体   繁体   中英

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?

.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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM