英文:
exec not running command from Golang application
问题
我正在Debian环境中运行一个Go应用程序。我所有的开发都在OSX上进行,它可以正常运行,但是我在我的Go代码中运行shell命令时遇到了问题。
cmdName := "cwebp"
cmdArgs := []string{srcPath, "-o", dstPath}
log.Printf("Executing %s : %+v", cmdName, cmdArgs)
cmd := exec.Command(cmdName, cmdArgs...)
_, err := cmd.StdoutPipe()
if err != nil {
log.Printf("Error: %s", err)
}
err = cmd.Run()
if err != nil {
log.Printf("Error: %s", err)
}
应用程序进程是以root用户身份运行的,当我从shell中运行该命令时,它可以正常工作。
之前,我认为我遇到了由于错误的PATH环境变量导致的问题。在运行命令之前打印出来的路径是正确的。此外,我尝试使用LookPath并得到了正确的路径/usr/local/bin/cwebp
。
英文:
I am running a Go application in a Debian environment. All my development has been carried out on OSX and it ran fine, but I am having a problem running a command on shell from my Go code.
cmdName := "cwebp"
cmdArgs := []string{srcPath, "-o", dstPath}
log.Printf("Executing %s : %+v", cmdName, cmdArgs)
cmd := exec.Command(cmdName, cmdArgs...)
_, err := cmd.StdoutPipe()
if err != nil {
log.Printf("Error: %s", err)
}
err = cmd.Run()
if err != nil {
log.Printf("Error: %s", err)
}
The application process is running from my root user and the command works fine when I run it from shell.
Earlier, I thought that I am facing the issue due to an incorrect PATH environment variable. On printing that before running the command, I get the correct path. Moreover, I have tried to use LookPath and got the correct path as /usr/local/bin/cwebp
.
答案1
得分: 0
问题不在于命令的执行,而是Go无法找到正确的库。在检查命令的输出时,我得到了以下信息:
cwebp: error while loading shared libraries: libwebp.so.5: cannot open shared object file: No such file or directory
这让我怀疑libwebp的安装可能存在问题。之前,我是通过源代码构建libwebp的。所以,我通过apt-get install libwebp-dev
安装了它,然后命令成功运行了。
英文:
The problem was not with the execution of the command but somehow Go was not able to find the correct library. On checking the output of the command, I got the following:
cwebp: error while loading shared libraries: libwebp.so.5: cannot open shared object file: No such file or directory
This led me to the direction that the installation of libwebp must have been faulty. Earlier, I had built libwebp from source. So, I installed it via apt-get install libwebp-dev
and the command ran successfully.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论