Running a bat file in background

15.5k Views Asked by At

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!

2

There are 2 best solutions below

0
On BEST ANSWER

Just run the command START start_STAF.bat.

0
On

For windows 10

  1. write .bat file(syncfiles.bat)
"C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe" --comment "linux_mint" --startvm "14f426cc-845d-46cb-9f6e-4dbb31a3769a"
  1. write .vbs file (start.vbs):
Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing
  1. run vbs file double click start.vbs