Batch script to launch an application

4

4

I've a simple batch script npp.bat to open a file in Notepad++

"C:\Program Files\(x86)\Notepad++\notepad++.exe" %1

Notepad++ launches with the file when I run npp <file_name&gt> but the command window waits for the application to exit. I don't want it to wait.

Abdulsattar Mohammed

Posted 2010-07-07T10:20:08.750

Reputation: 1 169

Answers

8

Use start instead:

start "" "command here"

Edit: Do not miss the first pair of empty quotes, this is the title of the process/window.

start <title> <command> <parameters>

See start /? for further details.

Bobby

Posted 2010-07-07T10:20:08.750

Reputation: 8 534

1That starts a new console window and the script runs there. I just want to start Notepad++ with the file and nothing else. Thanks in advance! – Abdulsattar Mohammed – 2010-07-07T10:54:32.893

2@CodingTales Be sure to include the first set of empty quotes. – heavyd – 2010-07-07T12:33:09.120

I missed the first "" and it didn't work. Thanks! – Abdulsattar Mohammed – 2010-07-07T21:05:45.687

3

I wanted to be able to do "npp file.txt" on the command prompt and be able to edit files using Notepad++. For this, I created a new folder, added it to Windows PATH, and created a file there called npp.bat with the following content:

@echo off
start "" "C:\Program Files\Notepad++\notepad++.exe" %1

Very useful when I'm working on the console and need to edit a file.

Nithin

Posted 2010-07-07T10:20:08.750

Reputation: 31

if your text editor is associated with txt files then won't it launch your text editor if you just type file.txt even without the npp? btw i have a similar setup with my text editors.. maybe even an npp.bat when I used notepad plus! You may want the %1 in quotes. in case the filename has a space, and you could experiment with a %* though no doubt you'd see if you had an issue an amend accordingly. – barlop – 2013-11-13T16:03:54.797

0

@Bobby method should work, If you directly calls the batch script ( double click ), the method will open a new command window. Instead use the following,

@echo off
start "C:\Program Files\Notepad++\notepad++.exe" blah.txt
cls
exit

If you replace blah.txt with %1, then you should pass the argument when you call the batch file.

ukanth

Posted 2010-07-07T10:20:08.750

Reputation: 9 930

2Missing the first set of quotes in the start command. That will open a new window with the title C:\Program Files\Notepad++\notepad++.exe and execute bla.txt – TheLQ – 2010-07-07T20:20:13.553

1Don't get me wrong, but 3 out of 4 lines of this script are unnecessary, in my eyes especially the exit. I hate people who put that into their scripts, because then I always have to restart the terminal from which I executed it. :/ – Bobby – 2010-12-29T08:06:54.343