繁体   English   中英

从 python 和 git-bash 运行脚本,如何删除“闪烁”

[英]run script from python and git-bash, how to remove "flashing"

我有以下 Python 脚本来执行 bash 脚本并捕获 output。

#!/usr/bin/env python3

import subprocess

def run(command):
    process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
    while True:
        line = process.stdout.readline().rstrip()
        if not line:
            break
        print(line)

run("hello_world.sh")
run("hello_world.sh")
run("hello_world.sh")

这是测试脚本。

#!/bin/bash

x=1
while [ $x -le 5 ]
do
  printf "Hello World $x times\n"
  x=$(( $x + 1 ))
  sleep 3
done

一切运行良好,除非每次开始运行时都会弹出一个新的 output window。 如果命令是系统命令(例如“ls -l”),则此行为不同。 这很不方便,因为我喜欢同一个 window 中的所有输出。

在流程定义中尝试shell=False

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM