Tuesday, April 25, 2006

Run an app in the background from a batch file

To save myself from typing "otepad" a few times a day, I put together a simple batch file, "n.bat", that would just run notepad.exe with the specified command-line arguments (if any). The file "n.bat" consisted of just a single line: @notepad.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

(The leading "@" character just causes the command not to be echoed to the command prompt window, which makes things look nicer; the "%1" through "%9" are the environment variables for the first 9 command-line arguments, which should be more than enough for any scenario that I'd ever use Notepad for!)

This worked fine, except that the command prompt window would wait/hang until the Notepad instance exited. (When n.bat was run from the Start | Run dialog, an empty Command Prompt window would appear until Notepad exited.)

To resolve this problem, I used the start command: @start notepad.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

No comments:

Post a Comment

Non-spammers: Thanks for visiting! Please go ahead and leave a comment; I read them all!

Attention SPAMMERS: I review all comments before they get posted, and I REPORT 100% of spam comments to Google as spam! Why not avoid getting your account banned as quickly -- and save us both a little time -- by skipping this comment form and moving on to the next one on your list? Thanks, and I hope you have a great day!