【问题标题】:run script from python and git-bash, how to remove "flashing"从 python 和 git-bash 运行脚本,如何删除“闪烁”
【发布时间】:2022-09-28 00:21:46
【问题描述】:

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

#!/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

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

    标签: python python-3.x bash git-bash


    【解决方案1】:

    在流程定义中尝试shell=False

    【讨论】:

      猜你喜欢
      • 2013-03-14
      • 1970-01-01
      • 2023-04-07
      • 2015-12-05
      • 1970-01-01
      • 2012-11-24
      • 2018-04-17
      • 1970-01-01
      • 2013-05-27
      相关资源
      最近更新 更多