{"id":2537,"date":"2017-12-09T04:54:01","date_gmt":"2017-12-09T04:54:01","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2537"},"modified":"2020-01-09T09:50:07","modified_gmt":"2020-01-09T09:50:07","slug":"get-the-application-exit-code-from-a-windows-command-line","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/get-the-application-exit-code-from-a-windows-command-line\/","title":{"rendered":"Get the application exit code from a Windows command line?"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: get the application exit code from a Windows command line?<\/strong><\/p>\n<p>Two ways&#8230;<\/p>\n<p>(1) The results are stored in a pseudo environment variable named errorlevel so&#8230;<\/p>\n<p>echo Exit Code is %errorlevel%<br \/>\n(2) and a special syntax of the if command:<\/p>\n<p>if errorlevel<br \/>\nsee if \/? for details.<\/p>\n<p>For Example<\/p>\n<p>@echo off<br \/>\nmy_nify_exe.exe<br \/>\nif errorlevel 1 (<br \/>\necho Failure Reason Given is %errorlevel%<br \/>\nexit \/b %errorlevel%<br \/>\n)<br \/>\nRegards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n<p><strong>rajeshkumar replied the topic: get the application exit code from a Windows command line?<\/strong><\/p>\n<p>:: Exit if a required file is missing<br \/>\n@echo off<br \/>\nIf not exist MyimportantFile.txt Exit \/b<br \/>\nEcho If we get this far the file was found<\/p>\n<p>:: Set the error level to 5<br \/>\n@echo off<br \/>\ncall :setError<br \/>\necho %errorlevel%<br \/>\ngoto :eof<\/p>\n<p>:setError<br \/>\nExit \/B 5<\/p>\n<p>To make this more flexible you can change the subroutine to set any errorlevel like this:<\/p>\n<p>:setError<br \/>\nExit \/B %1<\/p>\n<p>Now you can call the subroutine: call :setError 6 replacing 6 with whatever value you need the errorlevel to be set to.<\/p>\n<p>EXIT is an internal command.<br \/>\nRegards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rajeshkumar created the topic: get the application exit code from a Windows command line? Two ways&#8230; (1) The results are stored in a pseudo environment variable named errorlevel so&#8230; echo&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[57],"tags":[333],"class_list":["post-2537","post","type-post","status-publish","format-standard","hentry","category-scripting","tag-command"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2537"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2537\/revisions"}],"predecessor-version":[{"id":2538,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2537\/revisions\/2538"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}