我有一个PowerShell脚本,它使用du.exe(最初来自Sysinternals的磁盘使用情况)来计算目录的大小.
如果我du c:\Backup在控制台中运行,它按预期工作,但在ISE或PowerGui中运行的相同代码行给出了预期的结果加上错误
+ du <<<< c:\backup
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Run Code Online (Sandbox Code Playgroud)
这是为什么?如何避免此错误?我尝试使用invoke-expression &,但是没有去.
谢谢您的帮助.
在PowerShell中,git checkout运行时没有任何错误消息.在ISE中,当git checkout静止不动时,ISE会给出错误消息.
> git checkout master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
git : Switched to branch 'master'
At line:1 char:1
+ git checkout master
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Switched to branch 'master':String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Run Code Online (Sandbox Code Playgroud)
这不是一个主要问题,因为git checkout仍然有效.但这很烦人,所以我想知道为什么ISE会在标准的PowerShell没有时抱怨,更重要的是,我们怎样才能防止这种烦恼.
我看过为什么Powershell ISE显示Powershell控制台没有显示的错误?,这解释了ISE只是显示正常shell正在经历的内容.这个答案并不能解释如何平息这种烦人的行为.
作为我正在运行的脚本的一部分git clean -fd。它通常会输出一堆已清理的文件。我想抑制这个输出。
我尝试过git clean -fd | Out-Null,但似乎不起作用。git谷歌搜索没有返回抑制输出的选项,那么我可以使用另一种 PowerShell 方法吗?或者我做错了什么?值得注意的是,PowerShell 脚本本身是从.bat文件中执行的。