Batch command to open a program and load files into that program

A batch command is a command that can run certain programs or applications in Windows, either through a Command Prompt (CMD) or through text files with extensions.bat.

Batch commands can be useful for automating some repetitive tasks, such as opening programs, changing settings, or processing files.

In this article, we will discuss how to use batch commands to open a program, and then load a file into that program.

coding bw

Opening Programs with Batch Command

To open a program with a batch command, we can use the “start” command, which will run the program in a new window. The “start” command requires one parameter, namely the location or path of the executable file (.exe) that we want to run. For example, if we want to open Notepad, we can write the following command:

start C:\Windows\notepad.exe

The above command will open Notepad in a new window. If we want to close the window after the program has finished running, we can add the “/wait” option after the “start” command. This option will make the batch command wait until the program has finished running before proceeding to the next command. Example:

start /wait C:\Windows\notepad.exe

If we want to give a specific window name to the program we are running, we can add a second parameter after the start command, which is the name of the window we want. The name of this window must be given in quotation marks ( ““ ). Example:

start “My Notepad” C:\Windows\notepad.exe

The above command will open Notepad with the window name “My Notepad”. This window name can be useful if we want to control or modify the window with other commands, such as “taskkill” or “nircmd”.

Loading Files into Programs with Batch Command

To load a file into a program that we open with a batch command, we can use two ways, depending on the type of program and the file we use.

The first way is to give the location or path of the file we want to open as the third parameter after the “start” command. This usually works for programs that can accept files as arguments when run, such as Notepad, WordPad, Paint, or VLC. Example:

start “My Notepad” C:\Windows\notepad.exe C:\Projects\batch\hi.txt

The above command will open Notepad with the window name “My Notepad”, and then load the text file “hi.txt” into Notepad. If the file we want to open is not in the same folder as the batch file we are running, we must provide the full path of the file, like the example above. If the file is in the same folder as the batch file, we can use the relative path of the file. Example:

start “My Notepad” C:\Windows\notepad.exe hi.txt

The above command will open Notepad with the window name “My Notepad”, and then load the text file “hi.txt” which is in the same folder as the batch file.

The second way is to use the “call” command, which will run a program or another batch of files from within the running batch file. The “call” command requires one parameter, namely the location or path of the program or batch file we want to call.

The “call” command can also accept additional parameters that will be passed to the program or batch of files being called. This usually works for programs that cannot accept the file as an argument when executed, but have their commands for opening or processing the file, such as “MDXClient.exe”. Example:

call MDXCLIENT.exe input= “C:\MDX_Temp\Design_Ratings\Group_1\3-610\3-610.MDX” loadcase=1

The above command will run MDXClient.exe, and then pass two parameters to the program, namely input and loadcase. The input parameter indicates the location of the model file (. MDX) that MDXClient.exe wants to open, while the load case parameter indicates the case number that MDXClient.exe wants to process. The “call” command will wait until the invoked program has finished running before proceeding to the next command.

Conclusion

A batch command is a command that can be used to run certain programs or applications in Windows, either through Command Prompt (CMD) or through text files with extensions.bat. Batch commands can be useful for automating some repetitive tasks, such as opening programs, changing settings, or processing files.

To open a program with a batch command, we can use the “start” command, which will run the program in a new window. To load a file into a program that we open with a batch command, we can use two ways, depending on the type of program and the file we use.

The first way is to give the location or path of the file we want to open as the third parameter after the “start” command. This usually works for programs that can accept files as arguments when run, such as Notepad, Wordpad, Paint, or VLC.

The second way is to use the “call” command, which will run a program or another batch of files from within the running batch file. The “call” command can also accept additional parameters that will be passed to the program or batch of files being called. This usually works for programs that cannot accept a file as an argument when executed, but have their commands for opening or processing files, such as MDXClient.exe.

RELATED ARTICLES

Latest Articles