python - Read output from subprocess cli, yowsup-cli to store the output
问题描述
I have made the following subprocess to interact with the yowsup-cli
.
connection_string = "python /root/yowsup/yowsup-cli demos --yowsup --config config.json"
popen_parameters = connection_string.split(" ")
proc = Popen(popen_parameters, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
The interaction works fine I am able to send parameters but I have no return from the CLI of the yowsup-cli. the return is working in the background.
I need to send some variables from the input and receive the result from yowsup-cli
.
解决方案
我使用 Pexpect 并创建了一个算法来实现我的目标。对于那些需要创建自动化的人来说,这是我使用的:
child = pexpect.spawn('/bin/bash')
fout = open('mylog.txt','wb')
child.logfile = fout
child.sendline('/usr/bin/python /root/yowsup/yowsup-cli demos --yowsup --config config.json')
child.expect('offline')
bash
诀窍是在运行 python 脚本之前创建一个子进程。
在最后一行之后,child.expect('offline')
您可以按照适合您的海豚的逻辑发送所需的命令。
希望这对其他人有帮助
推荐阅读
- xmpp - 支持单个用户的多个窗口 - 使用 strophe.js 的 XMPP 聊天
- java - Android:使用 FLAG ACTIVITY CLEAR TOP 未完成上一个活动
- laravel - 当我在 Laravel 中更改主键时,SoftDelete 不起作用
- c# - 如何将十六进制字符串和十六进制字符串和十六进制字符串中的十进制值转换为字节
- web-services - 如何从外部的节点 js 客户端访问暴露的 BluePrism Web 服务
- android - MediaRecorder.AudioSource 中 VOICE_CALL 和 VOICE_COMMUNICATION 的区别
- docker - Kubernetes 中 NodePort 类型服务的 Pod 到 Pod 通信
- laravel - 将数据表添加到 laravel 混合文件
- mysql - SQL - 使用带有日期参数的查询,其中 IN 用于子查询
- python - 我如何获得与 keras 重合的百分比