[英]Getting the result of a Invoked-Expression in Powershell?
I need to test some archives in a Powerhsell script as I am automating the compression of a bunch of backup files with 7z
. 我需要在Powerhsell脚本中测试一些档案,因为我正在使用
7z
自动压缩一堆备份文件。
Now I know that normally when a program runs it returns 0 if everything completed normally; 现在我知道通常在程序运行时,如果一切正常完成,则返回0; but will return some other value if it did not complete normally.
但如果没有正常完成,将返回其他一些值。
For example we see here in Scheduled Tasks
that the Last Result displays 0x0
when the task completes successfully, and other values if it did not. 例如,我们在
Scheduled Tasks
中看到,当任务成功完成时,“最后结果”显示为0x0
,如果不成功,则显示其他值。
When I use Invoke-Expression
in Powershell to run 7z
to test the archive, I need to be able to pull the program return value to make sure that the archive tested successfully; 当我在Powershell中使用
Invoke-Expression
运行7z
来测试存档时,我需要能够提取程序返回值以确保存档测试成功; is there any way to get this value from Invoke-Expression
? 有没有办法从
Invoke-Expression
获取此值?
I'm calling the following command from Invoke-Expression: 我从Invoke-Expression调用以下命令:
7z t C:\backups\somezip.7z *.* -r
Also what is the value I'm talking about called? 我正在谈论的价值是什么? I know that if you write a program in C++ you return the value from the
main
method, but I'm not certain what it is called. 我知道如果你用C ++编写一个程序,你会从
main
方法返回值,但我不确定它的名称是什么。
You can enclose the paths in speechmarks ie 您可以将路径括在语音标记中
& "C:\\Program Files\\7-Zip\\7z" t "C:\\backups\\somezip.7z" *.* -r
and the value you are looking for is called $LASTEXITCODE
. 您要查找的值称为
$LASTEXITCODE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.