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

问题描述

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

'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/"')