Windows 等效于 Mac OS X“打开”命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/501290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:54:59  来源:igfitidea点击:

Windows equivalent of the Mac OS X “open” command

windowscommand-linecommand-line-interface

提问by jcnnghm

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

刘畅在这里提出了一个与此非常相似的问题,Linux 相当于 Mac OS X 的“打开”命令

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.

是否有与 Mac OS X“打开”命令等效的 Windows。我正在尝试运行一个分析器来打开它的结果,但它正在寻找“打开”命令。基本上,该命令需要从命令提示符打开文件,就像在资源管理器中双击一样。

回答by Charles Duffy

The closest thing available is start.

可用的最接近的东西是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!

感谢@Holger 指出这一点!

回答by Thomas Owens

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.

只需在控制台窗口中输入文件名即可在 Windows 中打开文件。我尝试了几种格式 - 用 OpenOffice 打开的 .doc、用 Windows Media Player 打开的 .mp3 和用写字板打开的 .txt。这与我在双击文件时遇到的行为相同。

回答by epatel

I use to write

我用来写

explorer.exe <file>

回答by Mitanshu

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

试试explorer <filename>。例如我想启动一个名为abc放置在桌面上的文件夹,所以我使用了命令

explorer abc

回答by Mike McKay

Only explorer.exe appears to work under cygwin.

只有 explorer.exe 似乎可以在 cygwin 下工作。

回答by Vimal__Frontend web

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

我再次回答这个问题,因为接受的答案不正确,它使用start命令(将 CMD 作为一个新实例打开),也因为根据我的等效项explorer.exe也被其他人提到,但没有按照它应该的那样进行澄清!

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 PClocation (whether it is recents or my computer or anything else)

然后您将打开默认的此 PC位置(无论是最近的还是我的电脑或其他任何东西)

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

如果您希望该文件/视频与其他程序一起打开/播放,只需写下带有完整路径的程序名称(如果它不在 PATH 系统变量中),然后是文件名,例如

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

回答by Scott Bartram

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

如果您使用 cygwin(或 git bash),这里有一个快速脚本技巧。将 EDITOR 更改为您想要的任何内容:

#!/bin/sh
# open

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

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

exit 0

回答by John Eis Clema

'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.

正如@charles-duffy 所说,“开始”绝对是最接近 Windows 的东西。根据您的项目,还有一些工具可以解决这个问题。

Node opnis a pretty great solution to be totally cross platform

Node opn是一个非常好的跨平台解决方案

回答by INAM

Use start
I am using Windows 10 and:

使用start
我使用的是 Windows 10 并且:

> start .          

Opens the current directory in File Explorer

在文件资源管理器中打开当前目录

> start text.txt

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

在 Notepad++ 中打开的文本文件(它被设置为我的默认 Txt 编辑器)

回答by idkn

if you're on xfce, and you have Thunar, you can run the command " Thunar . " to open graphically current folder

如果您使用的是 xfce,并且您有 Th​​unar,则可以运行命令“Thunar”。以图形方式打开当前文件夹