python2.7 芹菜(等待命令,检索输出)



首先,我不知道最终获得我想存档的功能的最佳方法是什么。

我的代码将执行以下操作:

@celery.task
def updateServerByID(sevrerID):
#run update task
os.system("samplecommadn to update server by id...")
#check if the output of the console contains "Success!", if yes, end job by using "return" statement
#return

以下是我认为运行代码的两种方法:

  1. 将控制台命令的输出重定向到文件(使用 python "监视"此文件的更改,并在每次更改时读取文件内容
  2. 检查控制台命令的输出是否为"成功!

总而言之,我认为方式 2 是最有效的,但是如何在 python 中读取整个控制台输出?有没有办法阻止芹菜任务本身打印此内容?

这与芹菜无关,它的作用是如何获得输出的 获取os.system的输出.
只需按照 [python-how-to-get-stdout-after-running-os-system] 获取celery.task.updateServerByID输出(Python:如何在运行 os.system 后获取 stdout?)

最新更新