- Create a batch file to run an .exe with an additional parameter
- 3 Answers 3
- Not the answer you’re looking for? Browse other questions tagged batch-file cmd or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Running Windows batch file commands asynchronously
- 7 Answers 7
- Bat file to run a .exe at the command prompt
- 11 Answers 11
- How to run an EXE file in PowerShell with parameters with spaces and quotes
- 19 Answers 19
- “Register” an .exe so you can run it from any command line in Windows
- 20 Answers 20
- Simple Bash-like aliases in Windows
- «Install» Your Aliases Path
- Add Your Alias
- Open in New Shell Window
- Execute in Current Shell Window
- Execute in Current Shell Window 2
Create a batch file to run an .exe with an additional parameter
I need a batch file which will do the following:
How can I do this?
I tried this but with no luck:
Update
I’ve used the solution provided by Ganesh (below) and came up with this:
I’ve tested it on a local machine (changing the directories) but on the server (with the directory above) it does not work.
The folder directory with batch file:
The error
3 Answers 3
in batch file abc.bat
I am assuming that your executible.exe is present in c:\user\ben_dchost\documents\ I am also assuming that the parameters it takes are -flag1 -flag2 -flag3
For the command you say you want to execute, do:
Hope this helps
Help on commands start and cd is output by executing in a command prompt window help start or start /? and help cd or cd /? .
But I do not understand why you need a batch file at all for starting the application with the additional parameter. Create a shortcut (*.lnk) on your desktop for this application. Then right click on the shortcut, left click on Properties and append after a space character «%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi» as parameter.
Found another solution for the same. It will be more helpful.
START C:\»Program Files (x86)»\Test\»Test Automation»\finger.exe ConfigFile=»C:\Users\PCName\Desktop\Automation\Documents\Validation_ZoneWise_Default.finger.Config»
finger.exe is a parent program that is calling config solution. Note: if your path folder name consists of spaces, then do not forget to add «».
Not the answer you’re looking for? Browse other questions tagged batch-file cmd or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Running Windows batch file commands asynchronously
How do I run all of them from a batch file asynchronously, i.e. without waiting for the previous program to stop?
7 Answers 7
Using the START command to run each program should get you what you need:
Every START invocation runs the command given in its parameter and returns immediately, unless executed with a /WAIT switch.
That applies to command-line apps. Apps without command line return immediately anyway, so to be sure, if you want to run all asynchronously, use START .
30 copy FILA DESTA and I wan them to be async, but I also want to have some idea when they’re all done. – Doug Jul 17 ’17 at 9:36
Combining a couple of the previous answers, you could try start /b cmd /c foo.exe .
For a trivial example, if you wanted to print out the versions of java/groovy/grails/gradle, you could do this in a batch file:
If you have something like Process Explorer (Sysinternals), you will see a few child cmd.exe processes each with a java process (as per the above commands). The output will print to the screen in whatever order they finish.
You can use the start command to spawn background processes without launching new windows:
The new process will not be interruptable with CTRL-C; you can kill it only with CTRL-BREAK (or by closing the window, or via Task Manager.)
Create a batch file with the following lines:
The start command runs your command in a new window, so all 3 commands would run asynchronously.
If the path to the program contains spaces remember to add quotes. In this case you also need to provide a title for the opening console window
If you need to provide arguments append them at the end (outside the command quotes)
Use the /b option to avoid opening a new console window (but in that case you cannot interrupt the application using CTRL-C
There’s a third (and potentially much easier) option. If you want to spin up multiple instances of a single program, using a Unix-style command processor like Xargs or GNU Parallel can make that a fairly straightforward process.
There’s a win32 Xargs clone called PPX2 that makes this fairly straightforward.
For instance, if you wanted to transcode a directory of video files, you could run the command:
Picking this apart, dir /b *.mpg grabs a list of .mpg files in my current directory, the | operator pipes this list into ppx2, which then builds a series of commands to be executed in parallel; 4 at a time, as specified here by the -P 4 operator. The -L 1 operator tells ppx2 to only send one line of our directory listing to ffmpeg at a time.
After that, you just write your command line ( ffmpeg.exe -i «<>» -quality:v 1 «<>.mp4″ ), and <> gets automatically substituted for each line of your directory listing.
It’s not universally applicable to every case, but is a whole lot easier than using the batch file workarounds detailed above. Of course, if you’re not dealing with a list of files, you could also pipe the contents of a textfile or any other program into the input of pxx2.
Bat file to run a .exe at the command prompt
I want to create a .bat file so I can just click on it so it can run:
Can someone help me with the structure of the .bat file?
11 Answers 11
To start a program and then close command prompt without waiting for program to exit:
Note: the first set of quotes must be there but you don’t have to put anything in them, e.g.:
it is very simple code for executing notepad bellow code type into a notepad and save to extension .bat Exapmle:notepad.bat
(above code «c:\windows\system32» is path where you kept your .exe program and notepad.exe is your .exe program file file)
Just put that line in the bat file.
Alternatively you can even make a shortcut for svcutil.exe, then add the arguments in the ‘target’ window.
A bat file has no structure. it is how you would type it on the command line. So just open your favourite editor..copy the line of code you want to run..and save the file as whatever.bat or whatever.cmd
Just stick in a file and call it «ServiceModelSamples.bat» or something.
You could add «@echo off» as line one, so the command doesn’t get printed to the screen:
If you want to be real smart, at the command line type:
Then you have CreateService.cmd that you can run whenever you want ( .cmd is just another extension for .bat files)
What’s stopping you?
Put this command in a text file, save it with the .bat (or .cmd) extension and double click on it.
Presuming the command executes on your system, I think that’s it.
As described here, about the Start command, the following would start your application with the parameters you’ve specified:
«svcutil» , after the start command, is the name given to the CMD window upon running the application specified. This is a required parameter of the start command.
«svcutil.exe» is the absolute or relative path to the application you want to run. Using quotation marks allows you to have spaces in the path.
After the application to start has been specified, all the following parameters are interpreted as arguments sent to the application.
How to run an EXE file in PowerShell with parameters with spaces and quotes
How do you run the following command in PowerShell?
C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe -verb:sync -source:dbfullsql=»Data Source=mysource;Integrated Security=false;User -dest:dbfullsql=»Data Source=.\mydestsource;Integrated Security=false;User >
19 Answers 19
When PowerShell sees a command starting with a string it just evaluates the string, that is, it typically echos it to the screen, for example:
If you want PowerShell to interpret the string as a command name then use the call operator (&) like so:
After that you probably only need to quote parameter/argument pairs that contain spaces and/or quotation chars. When you invoke an EXE file like this with complex command line arguments it is usually very helpful to have a tool that will show you how PowerShell sends the arguments to the EXE file. The PowerShell Community Extensions has such a tool. It is called echoargs. You just replace the EXE file with echoargs — leaving all the arguments in place, and it will show you how the EXE file will receive the arguments, for example:
Using echoargs you can experiment until you get it right, for example:
It turns out I was trying too hard before to maintain the double quotes around the connection string. Apparently that isn’t necessary because even cmd.exe will strip those out.
BTW, hats off to the PowerShell team. They were quite helpful in showing me the specific incantation of single & double quotes to get the desired result — if you needed to keep the internal double quotes in place. 🙂 They also realize this is an area of pain, but they are driven by the number of folks are affected by a particular issue. If this is an area of pain for you, then please vote up this PowerShell bug submission.
For more information on how PowerShell parses, check out my Effective PowerShell blog series — specifically item 10 — «Understanding PowerShell Parsing Modes»
UPDATE 4/4/2012: This situation gets much easier to handle in PowerShell V3. See this blog post for details.
“Register” an .exe so you can run it from any command line in Windows
How can you make a .exe file accessible from any location in the Windows command window? Is there some registry entry that has to be entered?
20 Answers 20
You need to make sure that the exe is in a folder that’s on the PATH environment variable.
You can do this by either installing it into a folder that’s already on the PATH or by adding your folder to the PATH .
You can have your installer do this — but you may need to restart the machine to make sure it gets picked up.
Windows 10, 8.1, 8
Open start menu,
- Type Edit environment variables
- Open the option Edit the system environment variables
- Click Environment variables. button
- There you see two boxes, in System Variables box find path variable
- Click Edit
- a window pops up, click New
- Type the Directory path of your .exe or batch file ( Directory means exclude the file name from path)
- Click Ok on all open windows and
restart your systemrestart the command prompt.
You can add the following registry key:
In this key, add the default string value containing the path to the exe file.
You have to put your .exe file’s path into enviroment variable path. Go to «My computer -> properties -> advanced -> environment variables -> Path» and edit path by adding .exe ‘s directory into path.
Another solution I personally prefer is using RapidEE for a smoother variable editing.
Rather than putting the executable into a directory on the path, you should create a batch file in a directory on the path that launches the program. This way you don’t separate the executable from its supporting files, and you don’t add other stuff in the same directory to the path unintentionally.
Such batch file can look like this:
Let’s say my exe is C:\Program Files\AzCopy\azcopy.exe
I can now simply type and use azcopy from any location from any shell inc command prompt, powershell, git bash etc
it’s amazing there’s no simple solution for such a simple task on windows, I created this little cmd script that you can use to define aliases on windows (instructions are at the file header itself):
this is pretty much the same approach used by tools like NPM or ruby gems to register global commands.
It is very simple and it won’t take more than 30 seconds.
For example the software called abc located in D:/Softwares/vlc/abc.exe Add the folder path of abc.exe to system environment variables.
My Computer -> Click Properties -> Click Advanced system settings -> Click Environment Variables
now you can just open cmd prompt and you can launch the software from anywhere. to use abc.exe just type abc in the command line.
- If you want to be able to run it inside cmd.exe or batch files you need to add the directory the .exe is in to the %path% variable (System or User)
- If you want to be able to run it in the Run dialog (Win+R) or any application that calls ShellExecute, adding your exe to the app paths key is enough (This is less error prone during install/uninstall and also does not clutter up the path variable)
You may also permanently (after reboots) add to the Path variable this way:
Right click My Computer -> Click Properties -> Click Advanced system settings -> Click Environment Variables
Simple Bash-like aliases in Windows
To get global bash-like aliases in Windows for applications not added to the path automatically without manually adding each one to the path, here’s the cleanest solution I’ve come up with that does the least amount of changes to the system and has the most flexibility for later customization:
«Install» Your Aliases Path
Add Your Alias
Open in New Shell Window
To start C:\path to\my program.exe , passing in all arguments, opening it in a new window, create c:\aliases\my program.bat file with the following contents(see NT Start Command for details on the start commmand):
Execute in Current Shell Window
To start C:\path to\my program.exe , passing in all arguments, but running it in the same window (more like how bash operates) create c:\aliases\my program.bat file with the following contents:
Execute in Current Shell Window 2
If you don’t need the application to change the current working directory at all in order to operate, you can just add a symlink to the executable inside your aliases folder:
Put it in the c:\windows directory or add your directory to the «path» in the environment-settings (windows-break — tab advanced)
Add to the PATH, steps below (Windows 10):
- Type in search bar «environment. » and choose Edit the system environment variables which opens up the System Properties window
- Click the Environment Variables. button
- In the Environment Variables tab, double click the Path variable in the System variables section
- Add the path to the folder containing the .exe to the Path by double clicking on the empty line and paste the path.
- Click ok and exit. Open a new cmd prompt and hit the command from any folder and it should work.
Use a 1 line batch file in your install:
run the bat file
Now place your .exe in c:\windows, and you’re done.
you may type the ‘exename’ in command-line and it’ll run it.
Another way could be through adding .LNK to your $PATHEX. Then just create a shortcut to your executable (ie: yourshortcut.lnk) and put it into any of the directories listed within $PATH.
WARNING NOTE: Know that any .lnk files located in any directories listed in your $PATH are now «PATH’ed» as well. For this reason, I would favor the batch file method mentionned earlier to this method.
In order to make it work
You need to modify the value of the environment variable with the name key Path , you can add as many paths as you want separating them with ; . The paths you give to it can’t include the name of the executable file.
If you add a path to the variable Path all the excecutable files inside it can be called from cmd or porweshell by writing their name without .exe and these names are not case sensitive.
Here is how to create a system environment variable from a python script:
It is important to run it with administrator privileges in order to make it work. To better understand the code, just read the comments on it.
Tested on Windows 10
You can find more information in the winreg documentation