Running into issues executing a PowerShell script from within Python.
The Python itself is simple, but it seems to be passing in \n
when invoked and errors out.
['powershell.exe -ExecutionPolicy Bypass -File', '$Username = "test";\n$Password = "password";\n$URL
This is the code in full:
import os
import subprocess
import urllib2
fetch = urllib2.urlopen('https://raw.githubusercontent.com/test')
script = fetch.read()
command = ['powershell.exe -ExecutionPolicy Bypass -File', script]
print command #<--- this is where I see the \n.
#\n does not appear when I simply 'print script'
So I have two questions:
- How do I correctly store the script as a variable without writing to disk while avoiding
\n
? - What is the correct way to invoke PowerShell from within Python so that it would run the script stored in
$script
?