@@ -9,13 +9,13 @@ package os
99import (
1010 "os"
1111 "os/exec"
12+ "runtime"
1213 "strings"
1314
1415 "github.com/go-python/gpython/py"
1516)
1617
1718func init () {
18-
1919 methods := []* py.Method {
2020 py .MustNewMethod ("getcwd" , getCwd , 0 , "Get the current working directory" ),
2121 py .MustNewMethod ("getcwdb" , getCwdb , 0 , "Get the current working directory in a byte slice" ),
@@ -172,18 +172,22 @@ func _exit(self py.Object, args py.Tuple) (py.Object, error) { // can never retu
172172
173173// os.system(command string) this function runs a shell command and directs the output to standard output.
174174func system (self py.Object , args py.Tuple ) (py.Object , error ) {
175- if len (args ) == 0 && ! ( objectIsString ( args [ 0 ])) {
175+ if len (args ) != 1 {
176176 return nil , py .ExceptionNewf (py .TypeError , "missing one required argument: 'command:str'" )
177177 }
178178 var cargs []string
179- _carg , err := py . ReprAsString ( args [0 ])
180- if err != nil {
181- return nil , py .ExceptionNewf (py .TypeError , "Unable to parse string" ) // this will never execute
179+ _carg , ok := args [0 ].(py. String )
180+ if ! ok {
181+ return nil , py .ExceptionNewf (py .TypeError , "str expected (pos 1), not" + args [ 0 ]. Type (). Name )
182182 }
183- carg := strings .ReplaceAll (_carg , "'" , "" ) // required
183+ carg := strings .ReplaceAll (string ( _carg ) , "'" , "" )
184184
185- cargs = strings .Split (carg , " " )
186- command := exec .Command (cargs [0 ], cargs [1 :]... )
185+ var command * exec.Cmd
186+ if runtime .GOOS != "windows" {
187+ command = exec .Command ("/bin/sh" , "-c" , carg )
188+ } else {
189+ command = exec .Command (cargs [0 ], cargs [1 :]... )
190+ }
187191 outb , err := command .CombinedOutput () // - commbinedoutput to get both stderr and stdout -
188192 if err != nil {
189193 return nil , py .ExceptionNewf (py .OSError , err .Error ())
0 commit comments