谷歌的Golang执行退出状态为2和1。

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

google golang exec exit status 2 and 1

问题

我想在Go语言中执行Android SDK平台工具中的dexdump。

我已经设置了PATH变量。(我使用的是Ubuntu 12.04)

这是我的代码:

package main

import (
    "bytes"
    "fmt"
    "log"
    "os/exec"
)

func main() {
    path, err := exec.LookPath("dexdump")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(path)

    cmd := exec.Command(path)
    var out bytes.Buffer
    cmd.Stdout = &out
    err2 := cmd.Run()
    if err2 != nil {
        log.Fatal(err2)
    }
    fmt.Printf("%q\n", out.String())
}

结果:
/home/gunwoo/android-sdk-linux/platform-tools/dexdump

2012/10/15 16:44:39 退出状态 2

退出状态 1

为什么Go找不到路径?

英文:

I want execute the dexdump in Android SDK platform-tools on Go language.

I already set the PATH variable. (I'm use Ubuntu 12.04)

Here is my code:

package main

import (
    "bytes"
    "fmt"
    "log"
    "os/exec"
)

func main() {
    path, err := exec.LookPath("dexdump")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(path)

    cmd := exec.Command(path)
    var out bytes.Buffer
    cmd.Stdout = &out
    err2 := cmd.Run()
    if err2 != nil {
        log.Fatal(err2)
    }
    fmt.Printf("%q\n", out.String())
}

Result:
/home/gunwoo/android-sdk-linux/platform-tools/dexdump

2012/10/15 16:44:39 exit status 2

exit status 1

why go doesn't find the path?

答案1

得分: 6

你没有为exec.Rundexdump命令提供任何参数,这可能会导致出现以下错误:

dexdump: 未指定文件
dexdump: [-f] [-h] dexfile...

-d : 反汇编代码段
-f : 显示文件头的摘要信息
-h : 显示文件头的详细信息
-C : 解码(还原)低级符号名称
-S : 仅计算大小

当你运行以下版本的程序时,你会得到什么输出?

package main

import (
	"bytes"
	"fmt"
	"log"
	"os/exec"
)

func main() {
	path, err := exec.LookPath("dexdump")
	if err != nil {
		log.Fatal("LookPath: ", err)
	}
	fmt.Println(path)
	cmd := exec.Command(path)
	var out bytes.Buffer
	cmd.Stdout = &out
	err = cmd.Run()
	fmt.Printf("%s\n", out.String())
	if err != nil {
		log.Fatal("Run: ", err)
	}
}
英文:

You don't provide any arguments for the exec.Run dexdump command, which possibly generates an error like:

dexdump: no file specified
dexdump: [-f] [-h] dexfile...

-d : disassemble code sections
-f : display summary information from file header
-h : display file header details
-C : decode (demangle) low-level symbol names
-S : compute sizes only

What output do you get when you run the following version of the program?

package main

import (
	"bytes"
	"fmt"
	"log"
	"os/exec"
)

func main() {
	path, err := exec.LookPath("dexdump")
	if err != nil {
		log.Fatal("LookPath: ", err)
	}
	fmt.Println(path)
	cmd := exec.Command(path)
	var out bytes.Buffer
	cmd.Stdout = &out
	err = cmd.Run()
	fmt.Printf("%s\n", out.String())
	if err != nil {
		log.Fatal("Run: ", err)
	}
}

huangapple
  • 本文由 发表于 2012年10月15日 15:48:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/12891294.html
匿名

发表评论

匿名网友

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

确定