Friday, May 8, 2020

Running a Windows Command Line Job in Background

If we want to run a Windows command line task in background, like UNIX's "&" do, we can do the following from the Windows command line,

start /B cmd /C call program [arg1 [...]]

We explain each part as follows,
  • /B is the command line option to the start command. The documentation of the command start states the following,
    • /B. 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.
  • cmd is the program to run from the command line, i.e., C:\Windows\System32\cmd.exe
  • /C is the command line option given to cmd. The manual states,
    • /C. Carries out the command specified by string and then terminates
  • call is a command to cmd, it is to "call one batch program from another." The program does not have to be batch program, and can be any executable file.
  • program is the program to be called by the call command.
  • arg1 [...] are optional one or more command line arguments given to program.
For example, if we'd like to to run a Java program HelloWorld from the command line in background, we would do,

start /B cmd /C call java HelloWord

A Unix equivalent of this command would be java HelloWorld &.

No comments:

Post a Comment