【发布时间】:2018-04-27 17:27:15
【问题描述】:
我正在 ISE 中调试一个 powershell 脚本,并在那里调用 sysinternals pskill 实用程序。
由于某种原因,PowerShell 会打开以下对话框:
为什么?如何将其配置为不显示对话框,而只是按照我的意图运行脚本?
编辑 1
问题很容易重现:
- 运行 ise -noprofile
- 在 ise 命令提示符内运行 pskill -h
结果如下:
虽然没有对话框,但有错误输出,我想这是我在其他场景中出现对话框的原因。那么,问题是错误输出的原因是什么?
似乎 pskill 将其帮助屏幕的一部分发送到 stderr,确实,观察:
C:\Dayforce\utils> .\pskill.exe -h
PsKill v1.15 - Terminates processes on local or remote systems
Copyright (C) 1999-2012 Mark Russinovich
Sysinternals - www.sysinternals.com
Usage: pskill [-t] [\\computer [-u username [-p password]]] <process ID | name>
-t Kill the process and its descendants.
-u Specifies optional user name for login to
remote computer.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
C:\Dayforce\utils> .\pskill.exe -h 2> $null
Usage: pskill [-t] [\\computer [-u username [-p password]]] <process ID | name>
-t Kill the process and its descendants.
-u Specifies optional user name for login to
remote computer.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
C:\Dayforce\utils>
所以,我似乎只遇到了 pskill 的问题,因为它输出到 stderr 并且 ISE 认为这是打开对话框的好理由。我用 -nobanner 命令行选项修复它。
但是一般如何解决呢?如果命令输出 stderr,我不希望 ISE 打开任何对话框,这本身可能不是一个好习惯,但并不意味着有错误。
【问题讨论】:
-
添加
-Confirm:$false以禁止命令。Set-PSDebug -Offwill turn off debugging features. -
什么调试功能?我确实想要调试脚本的能力。在哪里添加
-Confirm:$false?
标签: powershell stderr powershell-ise