从 php 执行 shell 脚本会在 Windows (Xampp) 上打开文件


Executing shell script from php opens the file on Windows (Xampp)


我正在尝试从我的 PHP 文件运行脚本。当我运行脚本时,它只是打开我的记事本而不是执行文件。
我已经给了我的文件夹读写权限,尝试通过SSH运行(因为我与Vagrant一起工作)和cmd。但似乎没有任何效果。我认为我的代码是正确的,您可以在下面找到:

$output = shell_exec(getcwd()."/scripts/row.sh 2>&1");

有人可以帮助我吗?

这是因为您对.sh文件的OPEN WITH设置为 notepad

检查以下输出:

my_prompt> assoc .sh
.sh=sh_auto_file
    ^ ^ ^ ^ ^ ^ ^ <~~~~~~ Remember this name
my_prompt> ftype sh_auto_file <~~~~~~~~~~Use it here
sh_auto_file=%SystemRoot%'system32'NOTEPAD.EXE %1

您可以更改与以下项的关联:

my_prompt> ftype sh_auto_file=c:'cygwin'bin'bash.exe %1 %*

(根据您的设置更改 bash 的路径.exe...

有关更多详细信息,请在cmd.exe上运行命令assoc /? & ftype /?。(/?通常等同于 Linux 命令中的-h--help...

此外,对于更高级的用户,请签入注册表以获取HKCR'.shHKCR'sh_auto_file。您可以使用regedit