简体   繁体   English

如何在子进程中运行复杂的查询。在 python 中运行

[英]How to run complicated query in subprocess.run in python

I would like to run the following command using python subprocess.我想使用 python 子进程运行以下命令。

docker run --rm -it -v $(pwd):/grep11-cli/config ibmzcontainers/hpvs-cli-installer:1.2.0.1.s390x crypto list | docker 运行 --rm -it -v $(pwd):/grep11-cli/config ibmzcontainers/hpvs-cli-installer:1.2.0.1.s390x 加密列表 | grep 'cex4queue": []' grep 'cex4queue": []'

If I run using subprocess.call() - it is working.如果我使用 subprocess.call() 运行 - 它正在工作。 But I am not able to check the return value但我无法检查返回值

s1="docker run --rm -it -v $(pwd):/grep11-cli/config ibmzcontainers/hpvs-cli-installer:1.2.0.1.s390x crypto list | grep \'cex4queue\": []\'" p1 = subprocess.call(s1,shell=True) s1="docker run --rm -it -v $(pwd):/grep11-cli/config ibmzcontainers/hpvs-cli-installer:1.2.0.1.s390x 加密列表 | grep \'cex4queue\": []\' " p1 = subprocess.call(s1,shell=True)

Same command with subprocess.run is not working.与 subprocess.run 相同的命令不起作用。

I want to check whether that string present or not.我想检查该字符串是否存在。 How can I check?我该如何检查?

I would recommend the use of subprocess.Popem :我会推荐使用subprocess.Popem

import subprocess as sb

process = sb.Popen("docker run --rm -it -v $(pwd):/grep11-cli/config ibmzcontainers/hpvs-cli-installer:1.2.0.1.s390x crypto list | grep 'cex4queue\": []'".split(), stdout=sb.PIPE, stderror=sb.PIPE)

output, errors = process.communicate()

print('The output is: {}\n\nThe errors were: {}'.format(output, errors))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM