python 隐藏命令行窗口_python如何只执行cmd中的动作,但消除或隐藏cmd窗口 - 小众知识...

本文探讨了如何在Python中调用CMD命令而不显示命令行窗口。尝试了使用`subprocess.call`设置`shell=False`,以及添加`/Q`参数,但未能解决问题。还研究了`@echo off`、`WinExec`、`CreateProcess`和`subprocess.Popen`等方法。尽管找到了一些解决方案,如通过`stdout=subprocess.PIPE`来隐藏输出,但在IDLE中测试时仍然会弹出CMD窗口。最后,建议进一步研究相关方法以彻底隐藏CMD窗口。
摘要由CSDN通过智能技术生成

【问题】

这里提到的,打包python中,由于python中调用windows的cmd去执行一些动作,所以打包后的python,结果还是会遇到,调用cmd窗口(执行了对应的命令后)一闪而过。

想要消除此cmd一闪而过的问题。

只希望运行命令,执行动作。彻底不希望看到cmd的窗口显示出来。

【解决过程】

1.网上搜了搜,是关于python调用cmd的一些内容,所以说了:

设置shell为false,类似于:

subprocess.call('cmd.exe', shell=False, ......)

3.或者:

给cmd.exe 添加/Q参数,类似于:

subprocess.call('cmd.exe /Q', shell=False, ......)

但是结果不行:

有朝这方向想过,上面的我试过不行

shell默认为False,为真的话,unix下相当于args前面添加了 "/bin/sh" "-c",window下,相当于添加"cmd.exe /c",和隐藏shell窗口没关系吧

2.也去看了看,cmd本身的一些参数支持:

Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\CLi>cmd /?

Starts a new instance of the Windows command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]

[[/S] [/C | /K] string]

/C Carries out the command specified by string and then terminates

/K Carries out the command specified by string but remains

/S Modifies the treatment of string after /C or /K (see below)

/Q Turns echo off

/D Disable execution of AutoRun commands from registry (see below)

/A Causes the output of internal commands to a pipe or file to be ANSI

/U Causes the output of internal commands to a pipe or file to be

Unicode

/T:fg Sets the foreground/background colors (see COLOR /? for more info)

/E:ON Enable command extensions (see below)

/E:OFF Disable command extensions (see below)

/F:ON Enable file and directory name completion characters (see below)

/F:OFF Disable file and directory name completion characters (see below)

/V:ON Enable delayed environment variable expansion using ! as the

delimiter. For example, /V:ON would allow !var! to expand the

variable var at execution time. The var syntax expands variables

at input time, which is quite a different thing when inside of a FOR

loop.

/V:OFF Disable delayed environment expansion.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值