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

Hi spammers! No need to waste your time here; comments are heavily moderated, so if you like, you can save us both a little time and just move on to the next site. :-)

For everyone else: Thanks for visiting! Your comments are more than welcome!