相关疑难解决方法(0)

Powershell中的`$?`是什么?

$?Powershell 是什么意思?


编辑:TechNet在重言式中的答案,没有解释"成功"或"失败"的含义.

$?
包含上次操作的执行状态.如果上一次操作成功,则包含TRUE;如果失败,则包含FALSE.

我推测是$?只会测试$ LastExitCode是否为0,但我找到了一个计数器示例,其中$?是假,但$ LastExitCode为True.

powershell

47
推荐指数
2
解决办法
3万
查看次数

pwsh -命令正在删除引号

在 pwsh 中调用以下命令:

Write-Host '{"drop_attr": "name"}' 
Run Code Online (Sandbox Code Playgroud)

结果正常:

{"drop_attr": "name"}
Run Code Online (Sandbox Code Playgroud)

现在通过 pwsh 执行相同操作:

pwsh -Command Write-Host '{"drop_attr": "name"}'
Run Code Online (Sandbox Code Playgroud)

结果缺少引号和方括号?

drop_attr: name
Run Code Online (Sandbox Code Playgroud)

powershell

4
推荐指数
1
解决办法
3501
查看次数

如果程序失败,powershell 脚本将停止(如 bash `set -o errexit`)

如果程序失败,是否有一个优雅的 Powershell 脚本设置可以退出正在运行的 Powershell 脚本(或 shell 实例)?

我正在想象类似 Bash 功能set -o errexit(或set -e)但用于 Powershell 的东西。在该功能中,如果 bash 脚本中的程序失败(进程返回代码不是0),则 bash shell 实例会立即退出。

在 powershell 中,脚本可以检查$LastExitCode. 但是,对于每个程序调用来说,这变得很麻烦。也许powershell有一个功能可以自动检查程序返回码并做出反应。

在脚本中解释

Set-Powershell-Auto-Exit 'ProgramReturnCode'  # what should this be?
& program.exe --fail  # this program fails with an error code
& foo.exe             # this never runs because script has exited
Run Code Online (Sandbox Code Playgroud)

bash powershell

2
推荐指数
1
解决办法
249
查看次数

Windows Server 2019 上的 Azure 管道 powershell 和 git 在输出中出现错误

我的 azure 管道和我的一台服务器有问题。

失败的服务器是 Windows 2019 服务器。

如果我在 powershell 中调用 git,那么它会将所有警告和以下行视为错误。如果我在两台不同的服务器上做同样的事情 - 没有问题 - 即使输出相同。

这是返回的错误:

CD to  D:\web\test\testsite.com
 ##[error]git : Warning: Permanently added the RSA host key for IP address 'X' to the list of known hosts.
##[error]git : From bitbucket.org:SITE
##[error]At C:\azagent\A1\_work\_temp\c1ff2d2b-c773-4adc-9040-155e92a914bd.ps1:12 char:1
+ git pull origin master
+ ~~~~~~~~~~~~~~~~~~~~~~
##[error]    + CategoryInfo          : NotSpecified: (From bitbucket....b/fletcocarpets:String) [], RemoteException
##[error]    + FullyQualifiedErrorId : NativeCommandError
##[error] 
##[error]PowerShell exited with code '1'.
Run Code Online (Sandbox Code Playgroud)

Git 确实进行了拉动,实际上一切正常。但出于某种原因 - 在此服务器上 - azure 管道将文本视为错误。

任何想法为什么?很难在文本上正确解释问题。 …

powershell azure azure-devops azure-pipelines

1
推荐指数
1
解决办法
313
查看次数

标签 统计

powershell ×4

azure ×1

azure-devops ×1

azure-pipelines ×1

bash ×1