Windows running exe from command line

Run exe from bat file with command line arguments

I am building an install package and have a install directory , (obviously could change if user needed/wanted). in a subdir in the root install dir is a bat file that copies files , then runs a program , then runs another program. it currently looks like this.

the problem is that i need to add command line argument to the downsampling exe —max_old_space_size=3000

problem is in order to do this (under my current understanding of bat files which is limited) is to create a shortcut and input the command line argument in the usual windows shortcut way. I can’t create a relative shortcut and am not sure how best to do this. any ideas anyone ?

Ok so i have so far managed to create a bat file that creates a shortcut in the same dir using this script .

however I am not sure how to include the command line arguments into this file. if someone could give a thought that would be amazing.

d0 in your current code, you are pulling the letter drive from argument %0 – blaze_125 Oct 6 ’17 at 13:29

1 Answer 1

the cmd line arguments are available to you in the form %0 , %1 , %2 . With %

d0 in your current code, you are pulling the letter drive from argument %0 .

Weirdly enough, the link works if I click it, but does not for some users. Here’s the path if you’d like to copy paste it in your preferred browser. As you can see in the link, this is pulled from WindowsXP documentation, that may explain why the link is flaky at best.

EditIt seems like you want to call a program and pass that program a parameter as you are calling it. And you wish to start the program from a bat file. This is different than how I read your title.

Lets start with some basics. For reference sake, we’ll say the program I am using today is called GetToWork.exe

The program I am using GetToWork.exe offers me the ability to start it many different ways.

  • I can double click the exe which launches the program in a form
  • I can call the exe from CMD line and pass it parameters so it can do automated things without me having to do anything.
    1. I can pass the parameter —DontAskMeAnything if I want the program to do everything on its own.
    2. I can pass the parameter —AskMeForNewFile if I want the program to ask me before doing something to what it will consider to be a new file.
    3. I can pass it the parameter —DoItThisWayInstead if I want the parameter to do it a different way.

Now, I’m not the one who decided what parameters I can pass, nor what their result is going to be. In fact, the parameters were defined by the programmer who created the program. When he made the program, he decided that those were going to be the allowed parameters, and the actions related to them were going to be the actions that he decided. The programmer documented the parameters, and now I just want to use them because they make my life easier.

In order to trigger the parameter behaviors, I need to supply the said parameters to the program when I run it.

Читайте также:  Менеджер экранов для windows

If I wanted to trigger —DontAskMeAnything I would write this command:

If I wanted to trigger —AskMeForNewFile , then I would write this command:

If GetToWork.exe allows multiple parameters, I would maybe write something like this:

GetToWork.exe —AskMeForNewFile —DoItThisWayInstead

Now. back to you and your program. You are using a program called 10th-f-Downsampling.exe . We, I, don’t know that program. We, I, don’t know what the possible parameters are for that program. In order for you to know what you should pass, you’ll have to look up the documentation of that program. Sometimes just calling the exe with a /? is enough to get the parameter list. Again, this is dependant on the programmer who made the program as /? would simply be another parameter allowed by the programmer. And the result of the /? is usually to spit out the available parameters.

Lets break down your current code

  • Here, the program you are calling is xcopy
  • The first parameter you are passing to xcopy is %

d0\dir-files\record\*.*
The second parameter you are passing is «%

dp0input»

  • The third parameter you are passing is /Y
  • If you were to go into command prompt and run this command xcopy /? , you’d get a chunk of text showing you how to call the program, along with a list of parameters that can be passed. Although parameters are often recognized by name. their name has little meaning because once in the program, the programmer may have coded it so that only parameter position matters, or position and name, or whatever other cocktail of business rules he obliged by. Though it’s important to follow the directions if directions are provided in the documentation.

    How do I launch a program from command line without opening a new cmd window?

    I’m trying to programmatically execute an external file from cmd using this command:

    Where «filepath» is the path of my file. It opens fine but it also open a new command prompt window.

    So, which is the right command for opening an external program without opening a new window?

    9 Answers 9

    In Windows 7+ the first quotations will be the title to the cmd window to open the program:

    Formatting your command like the above will temporarily open a cmd window that goes away as fast as it comes up so you really never see it. It also allows you to open more than one program without waiting for the first one to close first.

    Add /B, as documented in the command-line help for start:

    Just remove the double quote, this works in Windows 7:

    If you want to maximize the window, try this:

    Your command START «filepath» will start a command prompt and change the command prompt title to filepath .

    Try to run start /? in windows command prompt and you will get more info.

    I think if you closed a program

    end, so if you want to start a program that you can use

    (/norma,/max/min are that process value cpu)

    start «filepath»

    if you want command line without openning an new window you write that

    start /b «filepath»

    /B is Start application without creating a new window. The application has ^C handling ignored. Unless the application enables ^C processing, ^Break is the only way to interrupt the application.

    If you’re doing it via CMD as you say, then you can just enter the command like so:

    which will open it within the same window. For example in C++:

    will open your.exe in the current CMD window. Likewise to start with a new window, just go for:

    If you go for the first option, you would have to clear your screen unless you wanted to have the command to open your.exe on the screen still.

    You can use the call command.

    Usage: call [drive:][path]filename [batch-parameters]

    For example call «Example File/Input File/My Program.bat» [This is also capable with calling files that have a .exe, .cmd, .txt, etc.

    NOTE: THIS COMMAND DOES NOT ALWAYS WORK.

    Not all computers are capable to run this command, but if it does work than it is very useful, and you won’t have to open a brand new window.

    “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,

    1. Type Edit environment variables
    2. Open the option Edit the system environment variables
    3. Click Environment variables. button
    4. There you see two boxes, in System Variables box find path variable
    5. Click Edit
    6. a window pops up, click New
    7. Type the Directory path of your .exe or batch file ( Directory means exclude the file name from path)
    8. 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):

    1. Type in search bar «environment. » and choose Edit the system environment variables which opens up the System Properties window
    2. Click the Environment Variables. button
    3. In the Environment Variables tab, double click the Path variable in the System variables section
    4. Add the path to the folder containing the .exe to the Path by double clicking on the empty line and paste the path.
    5. 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

    Читайте также:  Как скопировать код активации windows 10
    Оцените статью