Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute programs in the same directory as the windows batch file?

I have in the same folder a .bat and a .exe file. I couldn't call the .exe file from the .bat unless I put the full absolute path to it. Is there a way to don't specify the path?

like image 376
Jader Dias Avatar asked Apr 28 '10 15:04

Jader Dias


People also ask

How do I run an EXE from a batch file?

Create Batch File to Run EXESave your file with the file extension . bat , e.g. run-exe-program. bat and double click on it to run the .exe program.

Where are the two places you can execute a batch file from in Windows?

Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME. bat.

Can I run a program from a batch file?

In Windows you can run any program with the .exe extention from a batch file that is very useful in different automation scenarios. For example, you may want to create a batch file to use it as a launcher for the program that you want to execute with some parameters.

What is the current directory in a batch file?

What is the current directory in a batch file? Using the variables mentioned here, you can update run1.bat to call app1.exe with the following line: %~dp0app1.exe. (The %~dp0 variable includes a trailing slash.) This will tell the batch file to run the executable from the current batch file's location.

How do I run an EXE Program in Windows?

To create a batch file to run some .exe program in Windows, open a text editor (e.g. Notepad) and enter a command as follows: start "C:\Path\Program.exe" If you need to run a program with some additional parameters, you should also specify a "WindowName" just after the start command:

How do I run a batch script in Linux?

Type a name for the script — for example, first_advanced_batch.bat. After you complete the steps, double-click the .bat file to run it or use the steps below to execute the script with Command Prompt, File Explorer, or Task Scheduler.


1 Answers

Try calling the .exe with %~dp0, like this: %~dp0MyProgram.exe.

%0 contains the full path to the called .bat file.

~dp says to get the drive and path, including trailing \.

like image 97
Patrick Cuff Avatar answered Sep 28 '22 00:09

Patrick Cuff