【问题标题】:Python script wait before execution another scriptPython脚本在执行另一个脚本之前等待
【发布时间】:2016-05-09 14:42:53
【问题描述】:

我有一个 bash 脚本,里面有各种 python 脚本,我猜应该一个接一个地运行。

第一个是从网站下载种子的脚本,第二个是解压缩内容的脚本。

问题是 unrar 脚本不会等待 torrent 完成,所以我只得到了它的一部分。

有没有办法告诉脚本只有在种子完成时才开始?

【问题讨论】:

  • 您需要提供一些代码,否则这是一个猜谜游戏。

标签: python bash scripting libtorrent


【解决方案1】:

这是 bash 脚本。 dwtor.py下载torrent,unrar.py明显解压内容..等等..

#!/bin/bash

python dwtor.py                       

python unrar.py    

cd P2                                                 

python /home/disk/user/pyrocore/

【讨论】:

  • 为什么不按照上面的建议在 python 脚本中推送所有内容?否则这是一个 bash 问题,您可以在脚本中使用括号和 if 情况,例如: if ( echo "your_first_script" );then echo "WAS OK...second_script";else echo "error message";fi 再次更好的方法和控制你可以直接在python中找到。祝你有美好的一天。
【解决方案2】:

如果您使用 os.system 执行脚本,那么 EASY 解决方案可能是 导入操作系统

if (os.system("python script whatever") == 0):
    print("Your script was terminated and here you can add the rest)
else:
    print("Execution errors and do something else")

否则您可以检查其他答案,例如子流程模块:-)

如果有帮助,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-17
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 2012-06-26
    • 2017-08-09
    相关资源
    最近更新 更多