Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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
Python 如何在使用-File选项时关闭Powershell窗口_Python_Powershell_Popen_Windowless - Fatal编程技术网

Python 如何在使用-File选项时关闭Powershell窗口

Python 如何在使用-File选项时关闭Powershell窗口,python,powershell,popen,windowless,Python,Powershell,Popen,Windowless,我给Powershell打电话的方式如下: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noninteractive -nologo -file "C:\Users\dummy\Documents\dev\powershell\samples\test.ps1" 我是从python脚本调用它的,但是如果通过快捷方式调用,也会发现同样的问题。我原以为-NonInteractive标

我给Powershell打电话的方式如下:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noninteractive -nologo -file "C:\Users\dummy\Documents\dev\powershell\samples\test.ps1"
我是从python脚本调用它的,但是如果通过快捷方式调用,也会发现同样的问题。我原以为
-NonInteractive
标志会导致鲍威尔在隐藏窗口中执行,但事实并非如此。当从外部应用程序调用Powershell时,是否有办法抑制控制台窗口

基于Johannes Rössel建议的解决方案
您可以向控制台窗口传递适当的参数,也可以抑制控制台窗口


但是,PowerShell还有一个
-WindowStyle
参数,您可以将其设置为hidden。

使用
-WindowStyle hidden
。请参阅。

我没有幸使用了
-WindowStyle Hidden
,因为一段时间以来,每次都会出现一个控制台窗口

这就是为什么我使用一个名为PsRun.exe的助手exe来实现这一点。您可以下载源代码和exe文件。我用它来完成预定的任务


(请注意,-windowstyle参数仅适用于V2。)

仅供参考:我认为
-NonInteractive
只是说:不要发出提示。
import subprocess
st_inf = subprocess.STARTUPINFO()
st_inf.dwFlags = st_inf.dwFlags | subprocess.STARTF_USESHOWWINDOW
subprocess.Popen(["notepad"], startupinfo=st_inf)