I'm trying to understand the differences in behavior of a few PowerShell commands I can use in Windows 11 to open a text file:
1. `.ile_name.txt`
2. `start .ile_name.txt`
3. `notepad .ile_name.txt`
They all seem to open the text file in Notepad, either in a new tab if Notepad is already running, or in a new window if it isn't. But do these commands differ in how they are processed or interpreted behind the scenes? Also, just so you know, Notepad is currently the default application for .txt files on my system.
5 Answers
Here's a breakdown of each command's behavior:
- `.ile_name.txt` tries to run the file as a command, utilizing the system's file type associations. It needs the file to have Read and Execute permissions.
- `start .ile_name.txt` launches a process and looks for a match in the App Paths registry. It’s more versatile in terms of what it can execute.
- `notepad .ile_name.txt` directly calls the Notepad executable, which only checks the system path, not the current directory.
Also, make sure to quote your filenames with spaces correctly when using `notepad`!
You might want to consider using `Invoke-Item` as another option. Additionally, the call operator `&` can be useful for executing commands or scripts directly.
If you have Visual Studio Code installed, you could use `code .ile_name.txt` to specify it. This way, you're not relying on any default application, which might be safer if you're concerned about defaults changing.
Yes, if Notepad is set as the default app for .txt files, then PowerShell will use that when running commands. You can change the default app through Windows settings to whichever program you'd like. When you use `start` or don't specify an app, it defaults to whatever is set for that file type. What outcomes are you expecting with these commands?
I'd recommend using `notepad .ile_name.txt`. The other commands might work fine depending on your specific setup, but you might run into issues if your defaults change unexpectedly. Sticking with `notepad` ensures you're calling the app directly every time!
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures