如何查看由“subprocess.check_call()”执行的实际命令 [英] How to viewthe actual command executed by "subprocess.check_call()"

查看:984
本文介绍了如何查看由“subprocess.check_call()”执行的实际命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的命令

I have a command as given below

subprocess.check_call(["C:\\Program Files\\operation.exe", "execute", "-af", "createrecord.xml", " -stuName", student,"-gender" ,gender], shell=True)

当我手动运行这个命令,它工作正常。我相信subprocess.check_call()没有正确解析命令(可能是我的错误)。如何查看subprocess.check_call()的输出。

我想看到acutal命令的参数由subprocess.check_call()调用

When I run this command manually it works fine. I believe that the subprocess.check_call() has not parsed the command properly (probably my mistake). How to view the output of subprocess.check_call().
I'd like to see the acutal command with arguments as called by subprocess.check_call()

注意 - 我不想看到命令执行的返回值。我只是看看如何通过subprocess.check_call()格式化命令

NOTE - I don't want to see the return value of the command's execution. I only what to see how the command has been formatted by subprocess.check_call()

推荐答案

你应该使用列表形式 subprocess 只有(可能隐含) shell = False = True 。

You should use the list form of the subprocess stuff only with (possibly implicit) shell=False and the string form only with shell=True.

shell只能使用命令行工作,然后自行解析。没有shell,使用 exec *()函数,它们以分开的方式接受命令行参数。

The shell can only work with a command line which it then parses on its own. Without the shell, exec*() functions are usedm, which take the command line arguments in a separated way.

对于Windows,这只能保持一定的级别,但它仍然有效。

For Windows, this only holds up to a certain level, but it remains valid.

这篇关于如何查看由“subprocess.check_call()”执行的实际命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆