import subprocess # 用于执行 shell命令
def _run(command):
"""执行shell脚本命令,并实时打印输出"""
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
output = process.stdout.readline().decode().strip()
if output == '' and process.poll() is not None:
break
if output:
print(output)
def run(config):
instructs = ["python main.py"]
for key,val in config.items():
key = "--" + key
instructs.append(key)
instructs.append(str(val))
cmd = " ".join(instructs)
_run(cmd)
在jupyter notebook中执行shell脚本命令,并实时打印输出
于 2023-07-26 15:13:03 首次发布