Running powershell script within python script, how to make python print the powershell output while it is running

后端 未结 2 1740
青春惊慌失措
青春惊慌失措 2020-11-29 04:01

I am writing a python script which checks various conditions and runs a powershell script accordingly to help me automate migration from windows XP to windows 7. The powersh

2条回答
  •  臣服心动
    2020-11-29 04:33

    I don't have Python 2.7 installed, but in Python 3.3 calling Popen with stdout set to sys.stdout worked just fine. Not before I had escaped the backslashes in the path, though.

    >>> import subprocess
    >>> import sys
    >>> p = subprocess.Popen(['powershell.exe', 'C:\\Temp\\test.ps1'], stdout=sys.stdout)
    >>> Hello World
    _

提交回复
热议问题