英文:
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.Run的dexdump命令提供任何参数,这可能会导致出现以下错误:
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)
	}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论