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



我想通过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,然后在Linux命令中预加wsl

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

最新更新