Mohammad Amin Mohammad Amin - 1 year ago 77
Python Question

Passing "gets" c language function input parameter from an inline python code

How can I pass output of a Python script to gets function of a c program ? My c program code is below :

#include <stdio.h>
int main()
char name[64];
printf("%p\n", name);
puts("What's your name?");
printf("Hello, %s!\n", name);
return 0;

What I want to do is something like below:

$./a.out "$(python -c 'print "A"*1000')"

Thanks a lot.

Answer Source

To send data from the stdout of one command into the stdin of another command, you need a "pipe":

python -c 'print "A"*1000' | ./a.out

I assume that the buffer overrun here is deliberate, so I'll leave out the lecture about the unsafety of gets.

Normally, a command-line utility will acquire its input from the argument array (argv in the parameters to main), which usually avoids the need for copying the data and thus any risk if a buffer overrun.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download