Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to run *.exe in batch file 1

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
I got a batch file that compiles my code with qmake, nmake. Afterwards I start it calling the newly created exe. Now, how could i run this exe without knowing its filename e.g. applicatin.exe. The only thing I know is that it's the ONLY exe in the working directory. *.exe doesn't work. Any clue?

Cheers
 
hmm .. thats a tough one if *.exe doesnt run .... i supose you could always use this as a work around for now;

if that is the only .exe file in the folder ... then you can name all of your .exe files the same ... if they are in different folders them you should be safe.

just call them all app.exe ... and then you just app.exe listed in you batches and they will always find the appropriate file.

i dont know much about scripting ... but there are loads of sights online that should give you some pointers.
 
thanks buddies, but i think that doesn't help. I'll continue to search an post it here if i'll find something valueable.
 
john,

what does the %%a stand for? couldn't find anything in the net about this % is a variable i know, but double percent?
 
Double % is used in a batch file to represent a single %, if you were running it from the command line you would only use a single % symbol.

you need the double % symbols in a batch file to differentiate it from parameters (eg %1, %2, %3) which you will probably have come across.

John
 
I should clarify that in order for the above to work, the folder containing the files must be the current one; therefore if there is even a slim chance it won't, I would put a

cd \foldername

command above the for loop to switch to the correct location.

John
 
Hi John,

There should be no need to change to the target folder, for two reasons:
Firstly, if the folder is in the path (which could be set temporarily if need be), the exe file execute when called from another folder. Of course, there is alway the danger with this approach that, if you can't be sure your exe file's name isn't used elsewhere in the path, an exe file of the same name in another folder in the path might be executed instead.
Secondly, regardless of whether the folder is in the path, you could use:
for %%a in (*.exe) do \foldername\%%a

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top