【问题标题】:Combining bash and CMD in Linux under Windows 10在 Windows 10 下的 Linux 中结合 bash 和 CMD
【发布时间】:2018-03-12 08:38:57
【问题描述】:

我使用的是 Windows 10 下的 Linux 子系统。

例如,如果我有一个名为 x.pptx 的 PowerPoint 文件,我可以请求 Linux bash shell 请求 Windows 使用默认应用程序打开该文件。以下命令可以解决问题:

/mnt/c/Windows/System32/cmd.exe /C start x.pptx

但如果文件名包含空格(例如,x y.pptx),我就无法使用它。我想我已经尝试了单引号、双引号和反斜杠的所有可能组合。

我想做的事是否可能?

编辑

这是我的尝试:

使用 x\ y.pptx"x y.pptx"'x y.pptx'\"x y.pptx\" 只会打开 CMD 窗口。

使用 '"x y.pptx"' 会导致 Windows 说它找不到 y.pptx\(缺少的 x 和反斜杠不是拼写错误)。

使用 '\"x y.pptx\"' 会导致 Windows 说它找不到 y.pptx\\\(原文如此)。

【问题讨论】:

  • 你试过绝对路径吗? x y...在当前工作目录中吗? start 也有 /D 选项来指定目录
  • @NahuelFouilleul,是的,我尝试过使用绝对路径。是的,x y.pptx 在当前工作目录中。添加 /D 选项似乎没有帮助。
  • 在 cmd 中尝试各种 start 命令显示相同的结果使用 title 似乎是一种解决方法

标签: bash cmd windows-10 windows-subsystem-for-linux


【解决方案1】:

看来原因来自start命令:

来自start /?,似乎第一个引用的字符串被用作标题,给标题似乎是一种解决方法

start "title" "x y.pptx"

并从 bash 启动

/mnt/c/Windows/System32/cmd.exe /C start '"title"' 'x y.pptx'

【讨论】:

  • 它对我不起作用。我只是得到一个标题为“x y.pptx”的 CMD 窗口。 (start "title" "x y.pptx" 直接在 CMD 中执行时效果很好,但我无法从 bash 中得到它。)
  • 因为 bash 引用,更新答案
  • Nahuel,您的编辑不起作用,但这样做:/mnt/c/Windows/System32/cmd.exe /C start '"title"' 'x y.pptx'
猜你喜欢
  • 1970-01-01
  • 2017-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-05
  • 2020-01-21
  • 2016-09-22
相关资源
最近更新 更多