我如何 运行 linux 在 Windows XAMPP 上使用 shell_exec() 命令

How can I run a linux command on Windows XAMPP with shell_exec()

我想通过 shell_exec 在我的 php 脚本中 运行 执行 sed 命令,但出现以下错误:

'sed' is not recognized as an internal or external command,
operable program or batch file.

这是因为 XAMPP 使用 windows shell.
有什么方法可以将它配置为使用 linux shell?

PHP shell_exec 将尝试 运行 主机系统中的命令。 因此,您不能在 windows.

上执行 运行 linux 命令

如果你真的想在 windows 中尝试 运行 并且你有 windows 10 也许你可以尝试使用 wsl ( windows 子系统 linux )

感谢@SKos 和@lit,我找到了解决方案,只需安装 Windows Subsystem for Linux 然后将 wsl 添加到 linux 命令。

shell_exec('wsl sed "s/abc/def/"')