【问题标题】:Executing shell script from php opens the file on Windows (Xampp)从 php 执行 shell 脚本会在 Windows (Xampp) 上打开文件
【发布时间】:2023-03-11 15:30:01
【问题描述】:


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

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

谁能帮帮我?

【问题讨论】:

  • 我几乎没有使用 MS-Windows 的经验,但是您确定可以在该系统下使用 unix 典型的2>&1 吗?还可能值得探索在系统内注册了哪些“默认应用程序”来处理“*.sh”文件。
  • 是的,我想是的。 2>&1 似乎在我上次检查时有效。如果没有2>&1,它也会打开一个记事本。我来看看 windows .sh 处理程序
  • 2>&1 适用于 windows (cmd) 和 linux (*sh)

标签: php bash shell laravel xampp


【解决方案1】:

这是因为您的OPEN WITH 用于.sh 文件设置为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

【讨论】:

  • 然后。你让我走上正轨。仍在努力让它发挥作用,但现在我知道去哪里找了!
猜你喜欢
  • 1970-01-01
  • 2013-06-13
  • 2016-07-02
  • 1970-01-01
  • 2015-01-05
  • 1970-01-01
  • 1970-01-01
  • 2014-05-01
  • 1970-01-01
相关资源
最近更新 更多