[英]Calling a simple Golang executable from PHP failing with exec: “zip”: executable file not found in $PATH
尝试从 PHP 执行一个简单的 Golang 可执行文件
import (
"fmt"
"os/exec"
)
func main() {
out, err := exec.Command("zip").Output()
if err != nil {
fmt.Println("Error Executing the command: \n")
fmt.Printf("%s", err)
} else {
output := string(out[:])
fmt.Println("Command Executed successfully with Output \n" + output)
}
}
这是我的 php 调用脚本
<?php
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$output = shell_exec('zip 2>&1');
echo("Output of Calling zip command from PHP --> ".$output . "<br>");
$output = shell_exec('./genfilesdir/gotest 2>&1');
echo("Output of Calling zip command through golang --> ".$output);
?>
这里是PHP执行的output
Output of Calling zip command from PHP --> adding: -PK-�4PR��������- (deflated 0%) PKPK-�4PR�!-PK/M
Output of Calling zip command through golang --> Error Executing the command: exec: "zip": executable file not found in $PATH
当我尝试从命令行执行 golang 时,它可以工作
> sudo -u www-data ./gotest
Command Executed successfully with Output
P�4PR��������-PP�4PR�!-PK/M
这是环境细节
Apache/2.4.41 (Ubuntu 20.04) PHP 8.0.2 (cli) (内置: Feb 14 2021 14:21:37) (NTS)
我错过了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.