File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,24 @@ out, err := python.ExecutePython("script.py")
36
36
37
37
This will run a python script called ` script.py ` inside the virtual environment, using the proper command, analyzing files existence.
38
38
39
+ Alternatively, it is possible to get an instance for ` *exec.Cmd ` which can be handled independently.
40
+
41
+ ``` go
42
+ cmd := python.GetPythonRunCommand (" script.py" )
43
+ out , err := cmd.CombinedOutput ()
44
+ ```
45
+ or
46
+ ``` go
47
+ cmd := python.GetPythonRunCommand (" script.py" )
48
+ err := cmd.Run ()
49
+ ```
50
+ or
51
+ ``` go
52
+ cmd := python.GetPythonRunCommand (" script.py" )
53
+ err := cmd.Start ()
54
+ err = cmd.Wait ()
55
+ ```
56
+
39
57
#### Complete example
40
58
41
59
``` go
Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ func main() {
23
23
python .CleanUpVirtualEnv ()
24
24
python .SetupVirtualEnv ()
25
25
26
- out , err := python .ExecutePython ("script.py" )
27
-
26
+ cmd := python .GetPythonRunCommand ("script.py" )
27
+ out , err := cmd . CombinedOutput ()
28
28
if err != nil {
29
29
log .Error (fmt .Sprintf ("Job resulted in error: %s" , err .Error ()))
30
30
}
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ func getPythonCommand() string {
14
14
}
15
15
}
16
16
17
+ // GetPythonRunCommand Returns an *exec.Cmd to be handled with the provided "scriptName.py" using the python binary from virtual environment
18
+ func GetPythonRunCommand (scriptName string ) * exec.Cmd {
19
+ pythonPath := getPythonCommand ()
20
+ return exec .Command (pythonPath , scriptName )
21
+ }
22
+
17
23
// ExecutePython Executes the provided "scriptName.py" using the python binary from virtual environment
18
24
func ExecutePython (scriptName string ) ([]byte , error ) {
19
25
// run python job
You can’t perform that action at this time.
0 commit comments