如何制作启动 Bash 并运行命令的 Windows 快捷方式?

Kei*_*ith 8 windows bash shortcuts cmd.exe windows-subsystem-for-linux

我创建了一个 Windows 快捷方式,其目标看起来像

"C:\Windows\System32\bash.exe" php /c/script.php

(我知道我可以使用我的 php cli 的 Windows 版本来运行它,但出于好奇)

当我单击我的快捷方式时,它只是弹出一个 cmd 窗口并关闭(脚本应该需要几分钟才能运行。

有没有办法将命令通过管道传输到 Windows 上的 bash.exe?

Bis*_*iyo 11

首先,bash.exe 已被弃用。您应该wsl.exe在命令行中使用。使用 Windows Insiders Builds 17063 及更高版本来实现 WSL 中的互操作性功能。对于您的情况,这两种方法都可能有效:

wsl.exe php /mnt/c/MyFiles/test.php
wsl.exe --exec php /mnt/c/MyFiles/test.php
Run Code Online (Sandbox Code Playgroud)

以下是wsl.exe使用信息:

用法:wsl.exe [参数] [选项...] [命令]

运行 Linux 二进制文件的参数:

If no command line is provided, wsl.exe launches the default shell.

--exec, -e <Command>
    Execute the specified command without using the default Linux shell.

--
    Pass the remaining command line as is.
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请阅读WSL 与 Windows 的互操作性


Señ*_*Mas 9

如果这是 WSL,请使用bash.exe -c "command to run",

C:\Windows\System32\bash.exe -c "vi ~/.bashrc"

或者

C:\Windows\System32\bash.exe -c "p​​hp /mnt/c/script.php"