1

私は2つのファイルを持っています:

run.py

import subprocess
import time

while True:
  time.sleep(1)
  print 'hello'
  proc = subprocess.call(['./writer.sh'])

writer.sh (chmod 777'd)

#!/bin/sh
echo 'write something here'

そして、私は次の出力に混乱しています:

$ python run.py
hello
write something here
hello
write something here
hello
write something here
....

$ python run.py | tee out.log
write something here
write something here
(hello disappears)

....

$ python run.py > out.log
# Nothing, but out.log has the following:
write something here
write something here
write something here
write something here
hello
hello
hello
hello
... # and the two basically "expand" the longer I run this (instead of appending)

何が起こっているのですか?最初のコマンドのようにすべてを出力するにはどうすればよいですか?

4

1 に答える 1

2

メイン スクリプトの出力はバッファリングされます。sys.stdout.flush()サブプロセスを実行する直前に呼び出します。

于 2013-08-06T02:23:56.147 に答える