瀏覽代碼

fix an error in cookbook

wangweimin 3 年之前
父節點
當前提交
99593db468
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      docs/cookbook.rst

+ 3 - 2
docs/cookbook.rst

@@ -211,11 +211,12 @@ The following code shows how to redirect stdout of python code and subprocess to
         process = subprocess.Popen("ls -ahl", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         while True:
             output = process.stdout.readline()
-            if output == '' and process.poll() is not None:
-                break
             if output:
                 put_text(output.decode('utf8'), inline=True)
 
+            if not output and process.poll() is not None:
+                break
+
 
 Add missing syntax highlight for code output
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^