Calling C's hello world from Python
<p>My C script:</p>

<pre><code>/* Hello World program */

#include &lt;stdio.h&gt;

int main() {
   printf("Hello, World! \n");
   return 0;
}
</code></pre>

<p>I want to see <code>Hello, World!</code> get printed directly in my Python IDE (Rodeo IDE) in the <strong>easiest</strong> way possible.  </p>

<p>So far, I've come up with the following approach, but it doesn't seem to work (and is kind of cumbersome since it requires me to go to the Terminal):</p>

<p>First, I do <code>gcc helloworld.c</code> in the Terminal to generate the executable <code>a.out*</code>, and then I do:</p>

<pre><code>from subprocess import call
call(["./a.out"])
</code></pre>

<p>But instead of printing <code>Hello, World!</code> to the Python console, I just get <code>0</code> (which means success).  How can I instead make the C output print <em>directly</em> to the Python console, and how can I possibly simplify it even more (e.g., by avoiding a Terminal detour)?  I know I need to make the executable first (which is why I use Terminal) but maybe there's a sleeker way to do it within the Python IDE?  </p>

<p><strong>FOR USERS WONDERING WHAT THE b STANDS FOR... @happydave's solution is tested here and thanks to @Mark Tolonen for explaining the b</strong></p>

<pre><code>Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:52:12) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import subprocess
&gt;&gt;&gt; print(subprocess.check_output("./a.out"))
b'Hello, World! \n'
</code></pre>

<p>It is very strange where the <code>b</code> comes from...</p>

<pre><code>&gt;&gt;&gt; import subprocess
&gt;&gt;&gt; subprocess.check_output("./a.out")
'Hello World!\n'
</code></pre>

<p>Regarding your second question, you could also just call gcc using subprocess.  In that case, call is probably the right thing to use, since you presumably want to check for failure before running a.out.</p>

<p>Here's a full script:</p>

<pre><code>import subprocess
status = subprocess.call(["gcc","hello.c"])
if status == 0:
   print(subprocess.check_output("./a.out").decode('utf-8'))
else:
   print("Failed to compile")
</code></pre>

<p>hello.c:</p>

<pre><code>#include "stdio.h"
int main() {
   printf("Hello world!"); 
}
</code></pre>

<p>Output:
Hello world!</p>

python c rodeo