简体   繁体   中英

execute C program after building it, from batch file

Please help on how to execute ac program with gcc compiler using a batch file.
In my code it creates the exe file and closes.
When executing the batch for the second time it launches my c program.
But I need to launch the c program by executing the batch the first time.

My code looks like this:

@echo off
cd "C:\Users\karli\Desktop\MCAST\VilipsKarlis\VilipsKarlis"
start gcc -o Mystack.exe Mystack.c && Mystack.exe
exit

With the use of start you setup up a separate context to begin execution of gcc.
Then while that has not yet finished, you immediatly attempt to execute Mystack.exe .
It should fail to do so if the exe does not exist yet (maybe you want to provide more details on what happens in that situation).

When calling the second time, the exe exists and is successfully executed while gcc is still busy recreating it. The newly created program does not (yet) get executed.

Ie in order to get the exe started after gcc ended (successfully, because of your && ) you just need to delete the start .

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