Output of a Python input into C program
<p>Is it possible to do this? Output of a Python as input into C program.</p>

<p>You believe me if I say that this code before works?
Now it doesn't work. How can I make it work?</p>

<pre><code>python -c 'print "a" ' | ./myProgram
</code></pre>

<p>Simple example for myProgram:</p>

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

int main(int argc, char *argv[]){

  int i = 0;

  if(argc &gt; 0){
    for(i; i&lt;argc; i++){
      printf("%s\n", argv[i]);
    }
    printf("Done.");
  }
  return 0;
}
</code></pre>

<p>The input to your <code>C</code> code should be taken by <code>scanf</code>.</p>

<p>C code: <code>[test.c]</code></p>

<pre><code>#include &lt;stdio.h&gt;
int main() {
    int x;
    scanf("%d",&amp;x);
    printf("Value is %d\n",x);
}
</code></pre>

<p>Compile:</p>

<p><code>gcc test.c -o foo</code></p>

<p>Python code:<code>[test.py]</code></p>

<pre><code>print (3)
</code></pre>

<p>Command :</p>

<p><code>python test.py | ./foo</code></p>

<p>Output:</p>

<p><code>Value is 3</code></p>

<p>Here standard input of <code>C code</code> gets changed from <code>keyboard</code> to the end of pipe.
And standard output of <code>python code</code> gets changed from <code>monitor</code> to <code>beginning of pipe</code>.</p>

<p>In <code>C</code> there are kernel level calls to perform this operation. Read about <code>close()</code> , <code>dup()</code> calls. I hope your concept will be cleared then. Good Luck :)</p>

<p>And you are actually trying to print command line arguments. But look at your command. You are not passing any arguments to <code>myprogram</code>. So, <code>argc = 0</code>.</p>

python terminal pipe