Running a bat file in background

Nikhil Hegde picture Nikhil Hegde · Sep 30, 2017 · Viewed 10.2k times · Source

I've this .bat file which I'd like to run in the background. The file basically launches processes. The output of the .bat file would be:

X:\bin>start_STAF.bat
start_STAF.bat

X:\bin>X:\ActiveState\Perl\perl-5.14.0\bin\perl.exe x:\bin\start_STAF.pl

The operation completed successfully.
The operation completed successfully.
The operation completed successfully.
*
STAFProc is now Started.  Leave this window up.
*

Pressing the Enter key after a few minutes returns the control back to the prompt. I don't like this because this process needs to be launched through a Perl script and I don't know how one would automate the Enter key press through Perl.

There's a few things that I've tried, unsuccessfully.

I tried using START /B start_STAF.bat but what this does is that it returns back to the prompt without launching the .bat file. However, the next time I execute tasklist, the .bat file launches on stdout. This brings me back to square one.

I tried redirecting the stdout/stderr as start_STAF.bat >nul 2>&1 but this too, does not launch the .bat file.

Is there anything else that I can do? Thanks!

Answer

John Doe picture John Doe · Oct 12, 2017

Just run the command START start_STAF.bat.