subprocess.Popen() IO redirect

前端 未结 2 1568
旧巷少年郎
旧巷少年郎 2020-12-03 11:20

Trying to redirect a subprocess\' output to a file.

server.py:

while 1:
    print \"Count \" + str(count)
    sys.stdout.flush()
    count = count +          


        
2条回答
  •  遥遥无期
    2020-12-03 11:45

    Output redirection with ">" is a feature of shells - by default, subprocess.Popen doesn't instantiate one. This should work:

    server = subprocess.Popen(args, shell=True)
    

提交回复
热议问题