Skip to content

Commit 0db253e

Browse files
committed
Make ExecutePython usable from package
1 parent b61d029 commit 0db253e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56

67
log "github.com/sirupsen/logrus"
@@ -22,5 +23,10 @@ func main() {
2223
python.CleanUpVirtualEnv()
2324
python.SetupVirtualEnv()
2425

25-
python.ExecutePython("script.py")
26+
out, err := python.ExecutePython("script.py")
27+
28+
if err != nil {
29+
log.Error(fmt.Sprintf("Job resulted in error: %s", err.Error()))
30+
}
31+
log.Info(string(out))
2632
}

python/run.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package python
22

33
import (
4-
"fmt"
54
"os/exec"
6-
7-
log "github.com/sirupsen/logrus"
85
)
96

107
func getPythonCommand() string {
@@ -18,13 +15,9 @@ func getPythonCommand() string {
1815
}
1916

2017
// ExecutePython Executes the provided "scriptName.py" using the python binary from virtual environment
21-
func ExecutePython(scriptName string) {
18+
func ExecutePython(scriptName string) ([]byte, error) {
2219
// run python job
2320
pythonPath := getPythonCommand()
2421
cmd := exec.Command(pythonPath, scriptName)
25-
out, err := cmd.CombinedOutput()
26-
if err != nil {
27-
log.Error(fmt.Sprintf("%s", err.Error()))
28-
}
29-
log.Info(string(out))
22+
return cmd.CombinedOutput()
3023
}

0 commit comments

Comments
 (0)