M
M
Misha Shav2020-08-18 14:47:47
Python
Misha Shav, 2020-08-18 14:47:47

How to call powershell scripts from python?

Good afternoon, I want to run scripts (full-fledged, large and not so) on a python powershell. Recommended subproccess in this format. If I pass the command as an argument, it works, if the script does not work. Execution of unsigned scripts enabled. Tell me, please, darn
subprocess.Popen(['powershell', r'G:\test.ps1'])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2020-08-18
@SeanCooper

in my opinion it is easy to google
https://stackoverflow.com/questions/21944895/runni...
Desktop\test.ps1:
write-output 'test'
test.py:

# -*- coding: iso-8859-1 -*-

import subprocess, sys

p = subprocess.Popen(["powershell.exe",
              "C:\\Users\\<USER>\\Desktop\\test.ps1"],
              stdout=sys.stdout)
p.communicate()

python test.py
test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question