Sarvavyapi
Sarvavyapi

Reputation: 850

Run python script inside powershell script

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

Upvotes: 2

Views: 8069

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200533

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

print ("type=%s; ... = %s;" % (type, ..., timeDiff))

Upvotes: 4

Related Questions