Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Binary Files inside GoLang Program?

Tags:

go

I want to execute Binary Files inside GoLang Program.

Here is my code:

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    output, _ := exec.Command("/home/user/Golang/bin/hello").Output()
    fmt.Println(output)
}

But I get the output as: []

Thanks in advance.

like image 573
Test admin Avatar asked Nov 18 '16 05:11

Test admin


Video Answer


1 Answers

I can get the output.

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    output, err := exec.Command("/Users/duguying/gopath/bin/test").Output()
    if err!=nil {
        fmt.Println(err.Error())
    }
    fmt.Println(string(output))
}

check you binary file first or binary filepath is correcting. try to print out your error message.

like image 149
duguying Avatar answered Sep 20 '22 17:09

duguying