The Computer Oracle

Open file from the command line on Windows

Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: A Thousand Exotic Places Looping v001

--

Chapters
00:00 Question
00:28 Accepted answer (Score 67)
01:37 Answer 2 (Score 70)
01:51 Answer 3 (Score 16)
03:04 Answer 4 (Score 5)
03:21 Thank you

--

Full question
https://superuser.com/questions/246825/o...

Answer 2 links:
http://www.google.com
[here]: http://www.geoffchappell.com/studies/win...

Answer 3 links:
https://technet.microsoft.com/en-us/libr...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #commandline

#avk47



ANSWER 1

Score 72


If it is a registered extension, you can use "start" as in

start WordDoc.doc



ACCEPTED ANSWER

Score 69


If you are currently in the command prompt and have a file called test.png and , which are located in c:\test you can do the following:

If you are at the directory (so should say c:\test>) just type:

test.png

which would open test in the default png picture editor.

If the files name contains spaces, then simply enclose the file name within " "

 "this image.png"

You can alternatively type:

c:\test\test.png

which will open the file no matter where you currently are.

Finally, you can pass the picture to another program. For example, if you have an image editor called imageedit.exe and it supports opening files through command lines (and if the program is pathed/accessible or you are in it's current directory), you can type the following:

 imageedit c:\test\test.png



ANSWER 3

Score 5


powershell -c "folder\childfolder\file.txt"

Source: https://technet.microsoft.com/en-us/library/ee176882.aspx

Simple and versatile.




ANSWER 4

Score 3


The first parameter of Start is a window title, so if you have a space in the file name, and you type

Start "My File.txt"

you'll get a command line window with "My File.txt" as the title. To get around this use a dummy title,

Start "my title" "My File.txt"

Depending on the file and what application is opened there probably won't be a window to see anyway.