{"id":575,"date":"2018-03-14T09:36:52","date_gmt":"2018-03-14T09:36:52","guid":{"rendered":"http:\/\/imalogic.com\/blog\/?p=575"},"modified":"2018-03-14T10:00:02","modified_gmt":"2018-03-14T10:00:02","slug":"retrieve-the-errorlevel-for-windows-application","status":"publish","type":"post","link":"https:\/\/imalogic.com\/blog\/2018\/03\/14\/retrieve-the-errorlevel-for-windows-application\/","title":{"rendered":"Retrieve the &#8220;ErrorLevel&#8221; for windows application"},"content":{"rendered":"<body><p><\/p>\n<div class=\"answercell post-layout--right\">\n<div class=\"post-text\">\n<p>Testing <code><span style=\"font-family: Courier New;\">ErrorLevel<\/span><\/code> works for <em>console<\/em> applications, but this won\u2019t work if you\u2019re trying to run a <em>windowed<\/em> application (e.g. Win32-based) from a command prompt.<\/p>\n<p>A windowed application will run in the background, and control will return immediately to the command prompt (most likely with an <code><span style=\"font-family: Courier New;\">ErrorLevel<\/span><\/code> of zero to indicate that the process was <em>created<\/em> successfully).<\/p>\n<p>When a windowed application eventually exits, its exit status is lost.<a href=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/images.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"301\" data-permalink=\"https:\/\/imalogic.com\/blog\/2017\/05\/12\/c-functor\/images-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/images.jpg?fit=266%2C190&amp;ssl=1\" data-orig-size=\"266,190\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"images\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/images.jpg?fit=266%2C190&amp;ssl=1\" class=\"size-full wp-image-301 alignleft\" src=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/images.jpg?resize=266%2C190&#038;ssl=1\" alt=\"\" width=\"266\" height=\"190\" loading=\"lazy\"><\/a>Instead of using the console-based C++ launcher mentioned elsewhere, though, a simpler alternative is to start a windowed application using the command prompt\u2019s <code><span style=\"font-family: Courier New;\">START \/WAIT<\/span><\/code> command.<\/p>\n<p>This will start the windowed application, wait for it to exit, and then return control to the command prompt with the exit status of the process set in <code><span style=\"font-family: Courier New;\">ErrorLevel<\/span><\/code>.<\/p>\n<pre><code><span style=\"font-family: Courier New;\">start \/wait something.exe\r\necho %errorlevel%\r\n<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>Testing ErrorLevel works for console applications, but this won\u2019t work if you\u2019re trying to run a windowed application (e.g. Win32-based)<\/p>\n","protected":false},"author":1,"featured_media":578,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[24,79,78,77,75],"class_list":["post-575","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","tag-c","tag-cmd","tag-errorlevel","tag-mfc","tag-windows"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2018\/03\/windows.png?fit=259%2C194&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8J21V-9h","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts\/575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/comments?post=575"}],"version-history":[{"count":1,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions\/576"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/media\/578"}],"wp:attachment":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/media?parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/categories?post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/tags?post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}