2

I want to run a python script from inside a powershell script. All of my searches lead me to questions like THIS. I tried using Invoke-Expression, but a command window briefly opens and closes, without the expected output from the python script.

I also tried using the '&' operator, based on THIS question. This time, the script starts, but throws a SyntaxError. There is no such error when I run the python script separately.

EDIT: This is the command I run:

& $python $MyPythonScript

and the variables are set like this:

python="C:\Python33\python.exe"
MyPythonScript="D:\MyPythonScript.py"

This is the output:

File "D:\MyPythonScript.py", line 140
print "type=%s; mean = %s; finalVariance = %s; stdDev = %s; max(x) = %s; min(x) = %s; max(y) = %s; min(y) = %s; timeDiff = %s;" %(type, mean(distance), finalVariance, stdDev,    max(x), min(x), max(y), min(y), timeDiff)
                                                                                                                              ^
SyntaxError: invalid syntax
2
  • The & operator should do what you want. Please show the exact command line you're trying to run as well as the error it throws. Commented Oct 21, 2013 at 21:48
  • I have edited my question to show the script I run and the output. Commented Oct 21, 2013 at 21:54

1 Answer 1

4

That's a Python syntax error, not a PowerShell syntax error. Put the string interpolation in parentheses:

print ("type=%s; ... = %s;" % (type, ..., timeDiff))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.