25

Liu Chang asked a very similar question to this one here, Linux equivalent of the Mac OS X "open" command.

Is there a windows equivalent for the Mac OS X "open" command. I'm trying to run a profiler that will open it's results, but it's looking for the "open" command. Basically, the command needs to open a file from the command prompt as if it were double-clicked on in explorer.

Community
  • 1
  • 1
jcnnghm
  • 7,426
  • 7
  • 32
  • 38

9 Answers9

45

The closest thing available is start.


If its first argument is double-quoted, that argument is treated as a window title rather than a filename. Thus, to use it robustly, add an empty string as the first argument:

start "" "my filename.foo"

Thank you to @Holger for pointing this out!

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 4
    For me "start " just opens up a new instance of the command prompt. – Thomas Owens Feb 01 '09 at 18:17
  • Works from ConEmu. – Tatsh Jan 27 '17 at 20:10
  • 3
    Although this is terribly old: For those having the same problem than Thomas Owens: The syntax is `start "" <filename>`. That means, that if you put the filename in double-quotes you must specify a title (or you will just get another command shell window). However you may leave the title empty like this `start "" "<filename>"`.</filename></filename> – Holger Jan 29 '19 at 22:25
  • @Holger, ...ignore the now-deleted comments I first responded with -- I forgot this was Windows and was thinking MacOS/UNIX; on Windows, commands are passed a literal string with a full command line to parse themselves, so while that parsing is often done by the libc, they can indeed tell whether their arguments were quoted. – Charles Duffy Jan 29 '19 at 22:29
15

I use to write

explorer.exe <file>
epatel
  • 45,805
  • 17
  • 110
  • 144
11

Just typing the file name into a console window will open the file in Windows. I tried several formats - .doc opened with OpenOffice, .mp3 opened with Windows Media Player, and .txt opened with Wordpad. This is the same behavior I experience when double clicking on the files.

Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
3

Try explorer <filename>. For example I wanted to launch a folder named abc placed at desktop, so I used the command

explorer abc
clemens
  • 16,716
  • 11
  • 50
  • 65
Mitanshu
  • 31
  • 2
  • Welcome to Stack Overflow. When answering a question, please read the question carefully, and check that your answer is appropriate. In this case the OP wanted a command to open a file, rather than view a folder. – Jonathan Willcock Aug 06 '17 at 09:33
3

Use start
I am using Windows 10 and:

> start .          

Opens the current directory in File Explorer

> start text.txt

Opened text file in Notepad++ (It is set as my default Txt editor)

INAM
  • 31
  • 3
1

I am answering this again as the accepted answer is not correct which is using the start command (which opens up the CMD as a new instance) and also because The Equivalent according to me is explorer.exe as also mentioned by others but not clarified as it should have been!

So, If you want to open the current folder like that with the 'open' command. you should use

explorer.exe .

which will open the current folder in explorer or if you just do the

explorer.exe 

then you will open the default This PC location (whether it is recents or my computer or anything else)

It just works as in, when you just type in the file name it will just open in the default program just like

somevideo.mp4

and if you want that file/video to open/play with some other program just write down the program name with the full path (if it's not in the PATH system variable) followed by the filename like

"C:\program files\greentree applications\vlc.exe" somevideo.mp4
0

Only explorer.exe appears to work under cygwin.

Mike McKay
  • 2,388
  • 1
  • 29
  • 32
0

If you use cygwin (or git bash), here's a quick script hack. Change the EDITOR to be whatever you want:

#!/bin/sh
# open

EDITOR="exec subl.exe"
BROWSER="/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"

if [ -d "$1" ]; then
    exec explorer.exe $(cygpath -w "$1")
elif [ -f "$1" ]; then
    path=$(cygpath --windows "$1")
    case "$1" in
    *.xml) $EDITOR "$1";;
    *.txt) $EDITOR "$1";;
    *.html) "$BROWSER" "$path";;
    file://*) "$BROWSER" "$path";;
    http://*) "$BROWSER" "$path";;
    https://*) "$BROWSER" "$path";;
    esac
else
    # TODO non-existent file/dir
    echo "non existent file: $1"
    exit 1
fi

exit 0
0

'start' is definitely the closest thing for Windows as @charles-duffy stated. Depending on your project there are also a few tools out there that solve this problem.

Node opn is a pretty great solution to be totally cross platform

airborn
  • 2,547
  • 1
  • 15
  • 12