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>

<p>If you compile the C script (say, to <code>a.out</code>):</p>

<pre><code>#include &lt;stdio.h&gt;

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

<p>You can easily call it by using <a href="https://docs.python.org/3/library/ctypes.html" rel="nofollow">CTypes</a>:</p>

<pre><code># hello.py
import ctypes

beach = "./a.out"
seashell = ctypes.cdll.LoadLibrary(beach)

seashell.main()
</code></pre>

<p>Calling the following Python script will call your <code>main()</code> in your C script:</p>

<pre><code>$ python hello.py
Hello, World!
</code></pre>

<p>You can subprocess and capture the output using, for instance, <a href="https://docs.python.org/3/library/subprocess.html#popen-objects" rel="nofollow">communicate</a>, but there's no need to spawn a shell to accomplish what you're after.</p>

python c rodeo