I'm trying to call Python with the "-c" argument so that I can easily run arbitrary python code, for example: python.exe -c "for idx in range(10): print idx" Now this code works fine, from inside my batch file however, I am having problems when I want to do something more than that.
Consider the following Python code:
foo = 'bar' for idx in range(10): print idx
this will give you 0-9 on stdout. However, if I drop it on one line, using semicolons as separators, we get the following:
foo = 'bar';for idx in range(10): print idx
and try running it with python.exe -c , it will get a SyntaxError message:
C:\Python>python.exe -c "foo = 'bar';for idx in range(10): print idx" File "<string>", line 1 foo = 'bar';for idx in range(10): print idx ^ SyntaxError: invalid syntax
Does anyone know how I can use this without switching to a separate .py file?
I run this from the .cmd batch file using the call method:
call python.exe -c "blah blah"
with the same error generated.
source share