Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run exe file with parameters in a batch file

Tags:

Please have a look at my batch file.

echo off start "c:\program files\php\php.exe D:\mydocs\mp\index.php param1 param2" 

but it isn't working. Any ideas how do I get it working?

like image 477
user1421214 Avatar asked Apr 16 '14 14:04

user1421214


People also ask

How do I run an EXE from a batch script?

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.

How do I run an EXE from command line arguments in Windows?

You can test command line arguments by running an executable from the "Command Prompt" in Windows or from the "DOS prompt" in older versions of Windows. You can also use command line arguments in program shortcuts, or when running an application by using Start -> Run. This will start notepad with a blank document.

What is %% in a batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


2 Answers

This should work:

start "" "c:\program files\php\php.exe" D:\mydocs\mp\index.php param1 param2 

The start command interprets the first argument as a window title if it contains spaces. In this case, that means start considers your whole argument a title and sees no command. Passing "" (an empty title) as the first argument to start fixes the problem.

like image 133
nobody Avatar answered Sep 21 '22 03:09

nobody


If you need to see the output of the execute, use CALL together with or instead of START.

Example:

CALL "C:\Program Files\Certain Directory\file.exe" -param PAUSE

This will run the file.exe and print back whatever it outputs, in the same command window. Remember the PAUSE after the call or else the window may close instantly.

like image 33
Scopperloit Avatar answered Sep 21 '22 03:09

Scopperloit