在$PATH中找不到Unix可执行文件。

huangapple go评论85阅读模式
英文:

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>/目录中引起的,但事实证明,如果从主目录即~/执行,它也会成功运行。可能,就像评论中已经提到的那样,pwdls命令不在路径中,或者程序是以另一个用户身份执行的。

英文:

First I thought that the issue was caused because the code did not reside in ~/go/src/&lt;bitbucket.org&gt;/&lt;username&gt;/, 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.

huangapple
  • 本文由 发表于 2015年3月17日 16:31:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/29094410.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定