doutao4480 2012-10-15 07:48
浏览 629
已采纳

google golang exec退出状态2和1

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
", 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条回答 默认 最新

  • douwu8524 2012-10-15 08:37
    关注

    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
    ", out.String())
        if err != nil {
            log.Fatal("Run: ", err)
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究
  • ¥15 微服务假死,一段时间后自动恢复,如何排查处理
  • ¥50 webrtc-streamer TCP rtsp
  • ¥15 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计