I managed to get some working code for this by simply deleting the quote around the command itself:
package main import "fmt" import "os/exec" func main() { cmd := exec.Command("python", "-c", "import pythonfile; print pythonfile.cat_strings('foo', 'bar')") fmt.Println(cmd.Args) out, err := cmd.CombinedOutput() if err != nil { fmt.Println(err); } fmt.Println(string(out)) }
And of course, in the source you have this function (for Windows, at least I don't know if this works for other OSs):
// EscapeArg rewrites command line argument s as prescribed // in http://msdn.microsoft.com/en-us/library/ms880421. // This function returns "" (2 double quotes) if s is empty. // Alternatively, these transformations are done: // - every back slash (\) is doubled, but only if immediately // followed by double quote ("); // - every double quote (") is escaped by back slash (\); // - finally, s is wrapped with double quotes (arg -> "arg"), // but only if there is space or tab inside s. func EscapeArg(s string) string { ...
So, your code ends with passing the following command line call:
$ python -c "'import pythonfile; print pythonfile.cat_strings(\\"foo\\", \\"bar\\")'"
What, if checked, evaluates the string and returns nothing, therefore, output of length 0.
val
source share