consider the simple python program below which runs a powershell script. It works fine if I start the python program from the command line, even though I feel it’s odd it’s printing a blank line for the return value instead of 0. However, if I run this python program from pydev, the script hangs after calling subprocess.call(). I’m using Pydev 2.7.0 under Eclipse SDK 4.2.1 under Windows 7. Python version is 2.7.3.
import subprocess
def run_powershell_script(script):
cmd = ['powershell',
'-ExecutionPolicy',
'RemoteSigned',
'-File',
script]
returncode = subprocess.call(cmd)
print "Done"
return returncode
if __name__ == "__main__":
print run_powershell_script("testscript.ps1")
The powershell script I’m testing with is very simple: it prints the path and then returns 0:
Write-Host "$env:Path"
exit 0
So to recap I guess I have two questions, the most important being why subprocess.call() hangs when I run this program under pydev and the other question is why when I print the returncode I get a blank line instead of 0.
I’m not 100% here, but doesn’t
exitjust kill the script? To return a value when you exit to script, usereturn.. so Try this PS script instead: