python - 如何在两个一起工作的脚本完成后自动启动脚本?
问题描述
我实际上用一个shell命令运行了两个python脚本,但是当它们完成后如何自动运行第三个?
你知道我可以在同一个 .sh 中添加一个程序来做到这一点吗?
对于我使用的 .sh 文件:
python script1.py && python script2.py
我想在这个序列之后运行一个 script3.py。有人可以帮助我吗?
(显然我在终端上运行脚本
>chmod u+x shell.sh
>./shell.sh
此致。
解决方案
这将仅在前面的所有脚本都成功时执行每个后续脚本,也就是说,如果它们都以 status = 0 退出。请记住&&
在脚本之间添加:
python script1.py && python script2.py && python script3.py
例子:
执行所有 3 个脚本:
$ python -c 'print(1); exit(0);' && python -c 'print(2); exit(0);' && python -c 'print(3); exit(0);'
1
2
3
仅执行前 2 个脚本:
$ python -c 'print(1); exit(0);' && python -c 'print(2); exit(1);' && python -c 'print(3); exit(0);'
1
2
推荐阅读
- android - 排球 405 错误:com.android.volley.ClientError
- angular - 仅在需要时加载子元素
- python - 在numpy中提取一个不连续的子矩阵
- node.js - 出于安全原因,nodejs重新编码上传的文件....但是如何?
- c++ - 安全登山者 - 任务
- perl - 如何使用 Netldap 读取变量的内容
- c - Unix 中文件 I/O 中缓冲区大小的影响
- java - 在 java 2d arraylist 中搜索的麻烦?
- networking - LSTM 单元去哪儿了?
- angularjs - 为什么 Kendo Grid 内联不可编辑?