Reputation: 177
Please help on how to execute a c 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
Upvotes: 2
Views: 713
Reputation: 26753
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.
I.e. in order to get the exe started after gcc ended (successfully, because of your &&
) you just need to delete the start
.
Upvotes: 4