Windows PowerShell Exit Codes

PSMDTAG:FAQ: How can my script control the PowerShell exit code?

Answers:

  1. A normal termination will set the exitcode to 0
  2. An uncaught THROW will set the exitcode to 1
  3. The EXIT statement will stop the process and set the exitcode to whatever is specified.

c:\>powershell -noprofile -command "Write-output Test"
Test

c:\>echo %errorlevel%
0

c:\>powershell -noprofile -command "Write-output Test; throw 'ERROR'"
Test
ERROR
At line:1 char:25
+ Write-output Test; throw  <<<< 'ERROR'

c:\>echo %errorlevel%
1

c:\>powershell -noprofile -command "Write-output Test; exit 31492"
Test

c:\>echo %errorlevel%
31492

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

最新文章

  1. hibernate 异常:Unexpected Exception caught setting
  2. 中文乱码~Windows 7
  3. Android笔记——探究活动
  4. Tiffany
  5. 【题解】【字符串】【Leetcode】Valid Palindrome
  6. 【转】java 自动装箱与拆箱
  7. php正则过滤html标签、空格、换行符的代码,提取图片
  8. C#使用.net.mail配置163邮箱报错:不允许使用邮箱名称。 服务器响应为:authentication is required,smtp9,DcCowABHK4UYE11W2k6fAQ--.52196S2 1448940312
  9. 文本去重-----awk或者uniq
  10. 【mongodb系统学习之四】查看mongodb进程
  11. hystrix服务降级(3)
  12. vue 移动端屏幕适配 使用rem
  13. 给HTML页面指定元素添加属性,添加父元素
  14. Debian 9 VIM 使用鼠标右键复制
  15. CMake系列之四:多个源文件-多个目录
  16. jQuery选择器--:selected和:checked
  17. Spring源码解析二:IOC容器初始化过程详解
  18. ios网络请求
  19. java提取url里的域名
  20. Android应用自动更新功能的实现!

热门文章

  1. String中关于BeanFactory
  2. Vue和MVVM对应关系
  3. 安装cfssl证书生成工具
  4. python导出开发环境
  5. memcache 协议 &amp;&amp; Golang实现
  6. leetcode-15-basic-string
  7. AND和OR
  8. RSS列表
  9. 引用&amp;符号详解
  10. apache 虚拟主机配置(根据不同的域名映射到不同网站)