CreateProcess: space in a python command passed with -c
Question:
I am trying to port muon (a C99 implementation of meson) to Windows, and i have some problem with one of its unit tests. This unit test calls python3 with an array of C string, this array being:
"-c"
"print("some output")"
Note that this array can be any python script passed to the interpreter.
So I call CreateProcess() with lpApplicationName
being the string "C:Documentsmsys2mingw64bin/python3.exe"
and lpCommandLine
being "-c print("some output")"
(I have prepended
before each "
that I find in the string in the above array)
My problem is the space that is in the print() function. I get this error message:
err failed to run python3: File "<string>", line 1
print("some
^
SyntaxError: unterminated string literal (detected at line 1)
I can’t find a way to modify the string print("some output")
so that lpCommandLine
is correctly built.
Does someone have an idea how to do this ?
thank you
Answers:
Have you tried "print('some output')"
or 'print("some output")'
?
A user (I can’t remember the name) removed his answer and suggested to add "
around each option, and it worked. So I built the C string :
""-c" "print(\"some output\")""
and the tests were successful (except the last one, but this latter is related to lpEnvironment
argument of CreateProcess()
)
I am trying to port muon (a C99 implementation of meson) to Windows, and i have some problem with one of its unit tests. This unit test calls python3 with an array of C string, this array being:
"-c"
"print("some output")"
Note that this array can be any python script passed to the interpreter.
So I call CreateProcess() with lpApplicationName
being the string "C:Documentsmsys2mingw64bin/python3.exe"
and lpCommandLine
being "-c print("some output")"
(I have prepended before each
"
that I find in the string in the above array)
My problem is the space that is in the print() function. I get this error message:
err failed to run python3: File "<string>", line 1
print("some
^
SyntaxError: unterminated string literal (detected at line 1)
I can’t find a way to modify the string print("some output")
so that lpCommandLine
is correctly built.
Does someone have an idea how to do this ?
thank you
Have you tried "print('some output')"
or 'print("some output")'
?
A user (I can’t remember the name) removed his answer and suggested to add "
around each option, and it worked. So I built the C string :
""-c" "print(\"some output\")""
and the tests were successful (except the last one, but this latter is related to lpEnvironment
argument of CreateProcess()
)