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

Viewed 18

I have the following Python script to execute bash script and capture 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")

This the test script.

#!/bin/bash

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

Everything runs well, except whenever run is started a new output window will pop out. This behavior is different if the command is a system command (e.g. "ls -l"). It is very inconvenient as I like all the outputs in the same window.

0 Answers
Related