运行多个python的linux bash脚本 [英] linux bash script running multiple python

查看:367
本文介绍了运行多个python的linux bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个python脚本a.py和b.py 我想编写一个bash脚本,它将加载a.py,直到a.py完成后才运行b.py. 简单地

I have 2 python scripts a.py and b.py and I want to write a bash script that will load a.py and not run b.py until a.py is done doing it's thing. simplistically

#!/usr/bin/env bash
python a.py
python b.py

但这很幼稚,请检查a.py是否已完成...我该怎么做?

but this is naive, a check to see if a.py is done... how do I do that?

推荐答案

默认情况下,此命令将一个接一个地运行.

This by default will already run one after the other.

要检查python a.py是否已成功完成作为运行python b.py的必要条件,可以执行以下操作:

To check that python a.py completed successfully as a required condition for running python b.py, you can do:

#!/usr/bin/env bash
python a.py && python b.py


相反,尝试运行python a.py,并且如果python a.py未成功终止,则仅运行'python b.py':


Conversely, attempt to run python a.py, and ONLY run 'python b.py' if python a.py did not terminate successfully:

#!/usr/bin/env bash
python a.py || python b.py


要与后台进程同时运行它们:


To run them at the same time as background processes:

#!/usr/bin/env bash
python a.py &
python b.py &


(回应评论)-您可以将它连续链接成几个命令,例如:


(Responding to comment) - You can chain this for several commands in a row, for example:

python a.py && python b.py && python c.py && python d.py 

这篇关于运行多个python的linux bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆