Open Notepad++ from PowerShell

PowershellNotepad++

Powershell Problem Overview


How can I open up a file in Notepad++ from the Powershell command line?

Powershell Solutions


Solution 1 - Powershell

Inside powershell I can simply use the start and get general results

to open a python file with notepad++ here is what I did.

Start notepad++ ex1.py

this will start notepad++ and load the file ex1.py assuming you are in the same directory as the .py file. You can change that by adding the full path name

start notepad++ c:\users\you\desktop\files\ex1.py

Hope this helps!

Solution 2 - Powershell

Because the default path contains spaces, you have to quote the path to the exe. However because PowerShell is also a scripting language. A string by itself is simply evaluated as a string e.g.:

C:\ PS> 'Hello world'
Hello world

So you have to tell PowerShell you want to invoke the command that is named by the string. For that you use the call operator & e.g.:

C:\ PS> & 'C:\Program Files (x86)\Notepad++\notepad++.exe'

or if notepad++ is in your path:

  C:\ PS> notepad++

or if you're in the same dir as the exe:

  C:\ PS> .\notepad++

Solution 3 - Powershell

To open Notepad++ with and create a new empty file in the current path

start notepad++ newFile.txt

To open Notepad++ with an existing file

start notepad++ apples.txt

To specify the path and open multiple files

start notepad++ fruits/apples.txt, fruits/oranges.txt, package.json

Solution 4 - Powershell

To extrapolate on the previous answers and tie them up in a tidy bow: If you want to open a file with spaces in the path or name:

. 'C:\Program Files (x86)\Notepad++\notepad++.exe' 'C:\Temp\File With Spaces.txt' 

or

& 'C:\Program Files (x86)\Notepad++\notepad++.exe' 'C:\Temp\File With Spaces.txt'

It can also be set it as an alias:

Set-Alias -Value 'C:\Program Files (x86)\Notepad++\notepad++.exe' -Name 'NotePad'
$FileWithSpaces = 'C:\T e m p\File With Spaces.txt'
NotePad $FileWithSpaces

The top line here can be copied into (one of) your $Profile .ps1 file(s) so you don't need to keep using Set-Alias in every new PS instance.

Solution 5 - Powershell

I know this is an old question, but I found a bit of a workaround, quite by accident, and it is extremely straightforward. If you install and maintain Notepad++ via Chocolatey (think apt-get for Windows, but built on top of NuGet), then you get a shim that can be invoked from the command line.

cinst notepad++

And even if you already have an existing installation of Notepad, you can still "install" it from Chocolatey, and it will pull in the existing installation and maintain it.

I use Chocolatey for as much as I possibly can, because you can update everything in one fell swoop.

After that, editing things from PowerShell is a snap. Like my PowerShell profile:

notepad++ $PROFILE

Hope this helps someone, or several someones!

Solution 6 - Powershell

In my case, I wanted to start Notepad++ with a file as an argument, and open as admin. I wanted to open one of the PowerShell profiles. I had to use the following command variation:

start-process -Verb runas -filepath "C:\Program Files (x86)\Notepad++\notepad++.exe"  "`"$($PROFILE.AllUsersAllHosts)`""

All the other variations didn't work, I think due to a space in the path of the file to be opened. So, you must escape the " as:

"He said `"This is fun.`""

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionConcerned_CitizenView Question on Stackoverflow
Solution 1 - PowershellTaku_View Answer on Stackoverflow
Solution 2 - PowershellKeith HillView Answer on Stackoverflow
Solution 3 - PowershellDevendra LattuView Answer on Stackoverflow
Solution 4 - PowershellScriptMonkeyView Answer on Stackoverflow
Solution 5 - PowershellMike LouxView Answer on Stackoverflow
Solution 6 - PowershelltarekahfView Answer on Stackoverflow