Windows equivalent of the Mac OS X “open” command

2019-03-18 06:42发布

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.

9条回答
姐就是有狂的资本
2楼-- · 2019-03-18 07:12

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

explorer abc
查看更多
等我变得足够好
3楼-- · 2019-03-18 07:12

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
查看更多
老娘就宠你
4楼-- · 2019-03-18 07:23

Only explorer.exe appears to work under cygwin.

查看更多
爷、活的狠高调
5楼-- · 2019-03-18 07:27

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!

查看更多
劳资没心,怎么记你
6楼-- · 2019-03-18 07:27

'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)[https://github.com/sindresorhus/opn] is a pretty great solution to be totally cross platform

查看更多
唯我独甜
7楼-- · 2019-03-18 07:29

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.

查看更多
登录 后发表回答