Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keep command line window open when running scheduled task executing batch file

I would like to have the console window kept open when running a scheduled task which executes a batch file. If I run it manually meaning execute the batch file the window stays open but through task scheduler it doesn't open but I can see the task is still running. I put a pause at the end to do this.

 @echo off 
 TITLE PROCESS_MGR
 tasklist /FI "IMAGENAME eq JOESMO.exe" | find /I "JOESMO.exe">nul &&(echo PROCESS 
 JOESMO.exe IS ALREADY RUNNING! 
 echo %DATE%
 echo %TIME%
 pause
 ) || (
 echo JOESMO PROCESS IS NOT RUNNING 
 cmd /c start "JOESMO.exe" "C:\Users\xxxx\Documents\
 Visual Studio 2010\Projects\Projects2013\JOESMO.exe"
 pause)

I found this suggestion cmd /k myscript.bat but having creating the task in task scheduler for windows server 2008 I am not sure where to apply this. I added /k to the add arguments box in edit action in task.

like image 597
vbNewbie Avatar asked Nov 27 '13 22:11

vbNewbie


People also ask

How do I keep a command prompt window open in a batch file?

Edit your bat file by right clicking on it and select “Edit” from the list. Your file will open in notepad. Now add “PAUSE” word at the end of your bat file. This will keep the Command Prompt window open until you do not press any key.

How do I stop cmd from closing after batch file?

If you want the command prompt cmd widnow to stay open after executing the last command in batch file –you should write cmd /k command at the end of your batch file. This command will prevent the command prompt window from closing and you'll get the prompt back for giving more commands in the cmd window.

How do I keep the command prompt window open?

Type the "cmd /k" parameter before every command to keep the window from closing.

How do I run a batch file without closing a window?

If you're creating a batch file and want the MS-DOS window to remain open, add PAUSE to the end of your batch file. This prompts the user to Press any key. Until the user presses any key, the window remains open instead of closing automatically.


1 Answers

In the Scheduled Task dialog, just before the name of the batch file it's going to run (it's labeled Program/script. You now have something like:

myscript.bat

Change it to

cmd 

Add the following to the **Add Arguments (optional) entry:

/k "C:\My Batch File Folder\MyScript.bat"

Tested on my system (Win7 64-bit), and it worked perfectly. I'm looking at the open command window it created as I type this text. :-)

like image 187
Ken White Avatar answered Oct 01 '22 19:10

Ken White