git clone
它的输出写到stderr
作为记录在这里.我可以使用以下命令重定向它:
git clone https://myrepo c:\repo 2>&1
Run Code Online (Sandbox Code Playgroud)
但是这会将所有输出(包括错误)重定向stderr
到stdout
.有没有办法将进度消息重定向到stdout
但仍然写入错误消息stderr
.
我在Powershell ISE(手动加载脚本并按F5)和Powershell控制台(执行脚本文件)中运行完全相同的script.ps1文件.它们都有效,但ISE显示控制台没有的错误.为什么?
代码是:
git push origin master
Write-Host "lastExitCode: $lastExitCode Last command was successful: $?"
Run Code Online (Sandbox Code Playgroud)
此代码在ISE中输出此错误:
git.cmd : Initializing to normal mode
At E:\script.ps1:28 char:4
+ git <<<< push origin master
+ CategoryInfo : NotSpecified: (Initializing to normal mode:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Initializing to normal mode
Everything up-to-date
lastExitCode: 0 Last command was successful: False
Run Code Online (Sandbox Code Playgroud)
这在控制台中:
Everything up-to-date
lastExitCode: 0 Last command was successful: True
Run Code Online (Sandbox Code Playgroud)
您可以看到成功状态也不一样.
我有一个运行外部EXE文件的脚本.当该EXE文件失败时(将errorlevel设置为1),PowerShell脚本将失败.
我正在运行curl.exe并得到这个:
- CategoryInfo:NotSpecified:(%Total%... Time Current:String)[],RemoteException + FullyQualifiedErrorId:NativeCommandError
如何忽略/捕获外部EXE文件的失败并继续我的脚本?
我正在尝试在 PowerShell ISE 中调试脚本,但我遇到了一个问题,其中一行的正常输出被 ISE 解释为错误
我已经能够简化这个问题的重现:我在https://www.openssl.org/related/binaries.html获得了任何版本的 openssl (我用 1.0.2d x86 来自链接存储库http:/ /slproweb.com/products/Win32OpenSSL.html )
我打开 Powershell ISE,导航到 exe 所在的位置并运行以下命令:
$ErrorActionPreference = "Stop"
$env:OPENSSL_CONF = ((Resolve-Path "openssl.cfg").Path)
&openssl.exe genrsa
Run Code Online (Sandbox Code Playgroud)
输出是红色的,开始是这样的:
openssl.exe : Loading 'screen' into random state - done
At line:1 char:1
+ &C:\Trayport\OpenSsl\openssl.exe genrsa
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Loading 'screen...om state - done:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Generating RSA private key, 2048 bit long modulus
Run Code Online (Sandbox Code Playgroud)
如果我在正常的 PowerShell 命令窗口中运行它,输出相同但为白色,不会被视为错误
Loading 'screen' into random state …
Run Code Online (Sandbox Code Playgroud) powershell openssl powershell-ise powershell-3.0 powershell-4.0
我有一个简单的 PowerShell 脚本来使文件夹与其 git 存储库保持同步。
Param(
[Parameter(Mandatory = $true)][string]$branch,
[string]$location,
[int]$depth
)
Get-ChildItem -Recurse -Directory -Depth $depth -Filter _$branch -Name -Path $location |
ForEach-Object {
Write-Output "`n$("{0:MM/dd/yy} {0:HH:mm:ss}" -f (Get-Date)): Getting latest from $location$_"
git -C $location$_ pull
} *>> logs\$branch.log
Run Code Online (Sandbox Code Playgroud)
当存储库已经是最新的时,它可以正常工作。但是,如果不是,则输出如下:
07/29/19 14:47:27:从某个路径获取最新信息 git :来自 https://gitlab.com/someplace 在某个地方\UpdateBranch.ps1:10 字符:5 + git -C $location$_ 拉 + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (来自 https://gi...n/somerepo:String) [], RemoteException + FullQualifiedErrorId : NativeCommandError b34e5d0..3ec9561 开发 -> 起源/开发 b6d33b1..65fb520 功能/功能 1 -> 原点/功能/功能 1 * [新分支] …