7

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?

2
  • What was the specific way of "I already set the PATH variable."? Commented Oct 15, 2012 at 7:59
  • I write "export PATH=$PATH:$HOME/android-sdk-linux/platform-tools" in .profile Commented Oct 15, 2012 at 8:12

1 Answer 1

6

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)
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! I expect to print dexdump usage comment without argument.
The usage message is probably going to stderr, not stdout. Also the program is returning a non-zero exit code when it prints the usage message, which triggers your log.Fatal(err2) command. If you want to see the output, set cmd.Stderr = &out and move fmt.Printf("%q\n", out.String()) to before your if err2 != nil line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.