<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=WEXITSTATUS_Example</id>
	<title>WEXITSTATUS Example - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=WEXITSTATUS_Example"/>
	<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=WEXITSTATUS_Example&amp;action=history"/>
	<updated>2026-05-13T12:16:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0-beta</generator>
	<entry>
		<id>https://www.theeggeadventure.com/wikimedia/index.php?title=WEXITSTATUS_Example&amp;diff=2389&amp;oldid=prev</id>
		<title>Brianegge: Created page with &quot;Example of how to use WEXITSTATUS &lt;geshi lang=&quot;c&quot;&gt;  #include &lt;iostream&gt;   void run(const char * cmd) {     printf(&quot;Executing command %s\n&quot;, cmd);     int status = std::system(...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=WEXITSTATUS_Example&amp;diff=2389&amp;oldid=prev"/>
		<updated>2012-07-03T12:13:41Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Example of how to use WEXITSTATUS &amp;lt;geshi lang=&amp;quot;c&amp;quot;&amp;gt;  #include &amp;lt;iostream&amp;gt;   void run(const char * cmd) {     printf(&amp;quot;Executing command %s\n&amp;quot;, cmd);     int status = std::system(...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Example of how to use WEXITSTATUS&lt;br /&gt;
&amp;lt;geshi lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void run(const char * cmd) {&lt;br /&gt;
    printf(&amp;quot;Executing command %s\n&amp;quot;, cmd);&lt;br /&gt;
    int status = std::system(cmd);&lt;br /&gt;
    printf(&amp;quot;raw status %d\n&amp;quot;, status);&lt;br /&gt;
    if (status == -1) {&lt;br /&gt;
        printf(&amp;quot;fork failed\n&amp;quot;);&lt;br /&gt;
    } else if (WIFEXITED(status)) {&lt;br /&gt;
        printf(&amp;quot;terminated with exit status %d\n&amp;quot;,&lt;br /&gt;
                 WEXITSTATUS(status));&lt;br /&gt;
    } else {&lt;br /&gt;
        printf(&amp;quot;terminated abnormally\n&amp;quot;);&lt;br /&gt;
        printf(&amp;quot;You can&amp;#039;t use WEXITSTATUS here, cause if you did you would get %d\n&amp;quot;, WEXITSTATUS(status));&lt;br /&gt;
    }&lt;br /&gt;
    printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;argc: %d\n&amp;quot;, argc);&lt;br /&gt;
    if (argc &amp;gt; 1) {&lt;br /&gt;
        printf(&amp;quot;prepare to die!\n&amp;quot;);&lt;br /&gt;
        return *(int*)(0);&lt;br /&gt;
    }&lt;br /&gt;
    run(&amp;quot;/bin/true&amp;quot;);&lt;br /&gt;
    run(&amp;quot;/bin/false&amp;quot;);&lt;br /&gt;
    run(&amp;quot;/bin/maybe&amp;quot;);&lt;br /&gt;
    run(&amp;quot;./a.out Oh no&amp;quot;);&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/geshi&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
argc: 1&lt;br /&gt;
Executing command /bin/true&lt;br /&gt;
raw status 0&lt;br /&gt;
terminated with exit status 0&lt;br /&gt;
&lt;br /&gt;
Executing command /bin/false&lt;br /&gt;
raw status 256&lt;br /&gt;
terminated with exit status 1&lt;br /&gt;
&lt;br /&gt;
Executing command /bin/maybe&lt;br /&gt;
sh: /bin/maybe: No such file or directory&lt;br /&gt;
raw status 32512&lt;br /&gt;
terminated with exit status 127&lt;br /&gt;
&lt;br /&gt;
Executing command ./a.out Oh no&lt;br /&gt;
argc: 3&lt;br /&gt;
prepare to die!&lt;br /&gt;
raw status 139&lt;br /&gt;
terminated abnormally&lt;br /&gt;
You can&amp;#039;t use WEXITSTATUS here, cause if you did you would get 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Brianegge</name></author>
	</entry>
</feed>