Go exec external python script and get the returned output
<p>In my Go file i use exec to run the external script:</p>

<pre><code>cmd := exec.Command("test.py")
out, err := cmd.CombinedOutput()
if err != nil {
    fmt.Println(err)
}
fmt.Println(string(out))
</code></pre>

<p>The python script it's executed fine, but the go <code>fmt.Println(string(out))</code> prints nothing. </p>

<p>The question it's how i should return the value from the Python script to be read back again from Go?</p>

<p>Python pseudo code:</p>

<p><code>def main():
    ...
    ...
    return value</code></p>

<p>I think i found the bug, you need to put the full path to "test.py"</p>

<p><strong>Test</strong></p>

<p>I have two files in a directory:
    test.py
    test.go</p>

<p>The <code>test.py</code> is:</p>

<pre><code>#!/usr/bin/env python3

print("Hello from python")
</code></pre>

<p>and <code>test.go</code> is:</p>

<pre><code>package main

import (
        "fmt"
        "os/exec"
)

func main() {

//cmd := exec.Command("test.py")
// I got an error because test.py was not in my PATH, which makes sense
// When i added './' the program worked because go knew where to find test.py
cmd := exec.Command("./test.py")
out, err := cmd.CombinedOutput()
if err != nil {
    fmt.Println(err)
}
fmt.Println(string(out))
}
</code></pre>

<p>And I get the following output:</p>

<pre><code>$ go run ./test.go 
Hello from python
</code></pre>

python go