英文:
Unix executable files not found in $PATH
问题
我在使用Go语言时遇到了一个问题。以下是我的代码:
package main
import (
"fmt"
"os/exec"
)
func main() {
output, err := exec.Command("pwd").Output()
fmt.Println(string(output), err)
output, err = exec.Command("ls", "-l").Output()
fmt.Println(string(output), err)
}
当我运行这段代码时,我得到了以下错误信息:
err exec: "pwd": 在 $PATH 中找不到可执行文件;
err exec: "ls": 在 $PATH 中找不到可执行文件
我正在使用的是 Ubuntu 14.04
操作系统。
英文:
I have a problem when using Go. Here is my code:
package main
import (
"fmt"
"os/exec"
)
func main() {
output, err := exec.Command("pwd").Output()
fmt.Println(string(output), err)
output, err = exec.Command("ls", "-l").Output()
fmt.Println(string(output), err)
}
When I run this, I get the following errors.
> err exec: "pwd": executable file not found in $PATH;
>
> err exec: "ls": executable file not found in $PATH
I'm using Ubuntu 14.04
.
答案1
得分: 0
首先,我认为问题是由于代码不位于~/go/src/<bitbucket.org>/<username>/
目录中引起的,但事实证明,如果从主目录即~/
执行,它也会成功运行。可能,就像评论中已经提到的那样,pwd
和ls
命令不在路径中,或者程序是以另一个用户身份执行的。
英文:
First I thought that the issue was caused because the code did not reside in ~/go/src/<bitbucket.org>/<username>/
, but it turns out that it will also run successful if it is executed from the home directory, i.e. ~/
. Probably, like already was mentioned in the comments, the commands pwd
and ls
were not in the path or the program was executed as another user.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论