Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python2.7芹菜(等待命令,检索输出)_Python_Python 2.7_Celery_Celery Task - Fatal编程技术网

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

python2.7芹菜(等待命令,检索输出),python,python-2.7,celery,celery-task,Python,Python 2.7,Celery,Celery Task,首先,我不知道最终获得我想要归档的功能的最佳方式是什么 我的代码将执行以下操作: @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 usin

首先,我不知道最终获得我想要归档的功能的最佳方式是什么

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

@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
以下是我认为让代码运行的两种方法:

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

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

    这与芹菜无关,问题在于如何获取操作系统的get output的输出
    只需在[python如何在运行os系统后获取stdout]()之后的
    Cellery.task.updateServerByID中获取输出即可。首先,谢谢,但使用此代码,python不会等到命令以某种方式完成后再获取输出。。。