Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何从命令行使用Chrome打开文件?_Bash_Google Chrome - Fatal编程技术网

Bash 如何从命令行使用Chrome打开文件?

Bash 如何从命令行使用Chrome打开文件?,bash,google-chrome,Bash,Google Chrome,我想用Google Chrome或来自bash终端的Chrome在当前目录中打开一个文件(index.html)(我使用的是Linux Mint 15)。命令是什么?我尝试了一些直观的方法,做了一些堆栈和谷歌搜索,但毫无效果,奇怪的是被忽略了(也许是痛苦的显而易见)。提前谢谢 hermes@hades ~/coding/.../public $ google-chrome index.html google-chrome: command not found hermes@hades ~/cod

我想用Google Chrome或来自bash终端的Chrome在当前目录中打开一个文件(index.html)(我使用的是Linux Mint 15)。命令是什么?我尝试了一些直观的方法,做了一些堆栈和谷歌搜索,但毫无效果,奇怪的是被忽略了(也许是痛苦的显而易见)。提前谢谢

hermes@hades ~/coding/.../public $ google-chrome index.html
google-chrome: command not found
hermes@hades ~/coding/.../public $ google-chromium index.html
google-chromium: command not found

至少在Ubuntu 12.04上,它是
/opt/google/chrome/chrome
;我还在
/usr/bin/google chrome

上找到了它的符号链接,只需键入程序名,然后键入文件:

google-chrome {file-path}
例:


搜索chromium您可以像搜索chromium浏览器路径文件一样进行

/opt/google/chrome/google-chrome --allow-file-access-from-files index.html

--允许从文件中访问文件
会让您放松一些,这对于使用本地文件进行测试非常有用。

试试看

 open {filename}

如果是
.html
文件,则应在默认浏览器中打开该文件

如果Chrome是您的主浏览器,则只需使用

see your_file.html

在(Windows上)bash shell中,您可以使用:

start myFilename.html

和打开文件夹:

explorer“C:\Program Files\Git”


添加供参考,因为我的搜索也在这里登陆。

此解决方案一直适用于我-
打开-一个“google\chrome.app”index.html
-其中“google\chrome.app”是您系统上chrome的名称/位置

如果Chrome是您的默认浏览器,只需-
openindex.html

  • 在bash或git CMD中,确保您位于项目目录/文件夹中
  • 键入
    start index.html
  • 按回车键。瞧:-)你完了
  • 这对我有用。希望它也能为您带来帮助。

    由于Chrome不是默认浏览器,这在Windows 10下对我很有效:

    start "New Chrome Window Title" /d "C:\Program Files (x86)\Google\Chrome\Application" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --new-window "file://C:/Folder/SubFolder/Sub Subfolder/thisfile.html"
    
    您需要:

    • 将非限定文件名转换为完全限定文件名的方法
    • 将反斜杠转换为正斜杠的方法
    • 在URL上添加“
      文件://
      ”前缀的方法
    • 识别您在其中找到chrome.exe的特定目录
    • 决定是否要保持开关以强制打开新窗口
    • 以及其他相关的命令行选项
    .bat
    .cmd
    文件中,使用
    FOR
    命令和
    SET
    命令的文本替换功能,可以合理地执行这些操作;或者在可以从批处理文件调用的
    .vbs
    .ps1
    脚本中执行所有这些操作,等等


    但是基本语法似乎很合理。

    正如其他人所说,解决方案是使用:

    google-chrome www.google.com
    
    您还可以使用
    --incognito
    在incognito模式下打开它们:

    google-chrome --incognito www.google.com
    
    注意:只需将多个页面依次放置,即可同时打开多个页面:

    google-chrome www.google.com www.yahoo.com
    
    如果要从文件中打开它们,请使用命令substitution
    $()
    将其打开并动态处理:

    google-chrome $(<file)
    

    google chrome$(适用于MacOS,在bash CLI中具有绝对路径(如果您的chrome安装在/Applications文件夹中)使用:

     /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
    
    因此,如果您想打开CNN网页:

     /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome  www.cnn.com
    

    可以使用以下终端命令打开文件 (Linux)

  • 在新选项卡中打开
    googlechrome
  • 在新窗口中打开
    googlechrome--新窗口
  • 以匿名模式打开
    googlechrome--Incognito(--Incognito模式)
  • =localhost/test/。/filename.html
    
    看起来Chrome不在您的$PATH中。简单的解决方案可能是卸载并重新安装Chrome,然后将其放入您的$PATH中。然后

    google-chrome [file] 
    
    应该对你有用。

    对于我正在使用的Mac电脑

    open -a 'google chrome' /yourPath
    
    试试这个

    start chrome "file or path"
    
    FireFox也是如此

    start firefox "file or path"
    

    这对我很有效。

    我所看到的其他东西都不适用于我,但我后来发现这一点很有效:


    explorer.exe index.html

    这对我不起作用…我将使用terminal outputok编辑上面的内容。我们需要找到您拥有的chrome。CD到
    /usr/bin
    并执行`
    查找。-name*chrome*
    如果您没有得到任何信息,请尝试
    查找。-name*chrome*
    让我知道您得到了什么。google-chrome不在/usr中/而且两者都不是chromium@neaumusic你有没有试过
    find/-name*chrom*
    ?你有没有安装过?@neaumusic是的,你必须先安装chrome。看起来你有mac。如果你将chrome设置为默认设置,你只需要
    打开{file}
    如果chrome被设置为默认浏览器,只需
    打开index.html
    。否则,
    打开-a(chrome位置)index.html
    至少在Mac上这应该是公认的答案。@chovy不幸的是,这与Mac无关。相关:对于那些试图安装chrome用于灯塔的人,必须安装chrome(v7)而不是chromium browser(v6)搜索让我也来到了这里,这正是我要寻找的。
    $chromium browser-bash:chromium browser:command not found
    @chovy这可能意味着你没有
    chromium browser
    。实现这一点的跨平台方法是
    python-m webbrowser{filename}
    。对于linux,
    xdg open{filename}
    通常会起作用。但同样,只有当chrome被设置为该文件类型的默认应用程序时,这种方法才起作用。open-a“google\chrome.app”--args--arg1=value1--arg2=value2
    open -a 'google chrome' /yourPath
    
    start chrome "file or path"
    
    start firefox "file or path"