I used to be able to pass input to C program by first writing a python script and using pipe to send it to the C program as an input

or write the output of python script to a file and just doing r < myfile in gdb

but how can i do this to pass argv arguments to a C function?

i need to pass a long argument and need to use print function of python to create the value, but i don't know how can i pass it to the C program? piping or using < doesn't work.

for example doing python x.py | myprogram didn't work, and using it after the myprogram like myprogram python x.py doesn't work either, how can i pass the output as an argv argument of this program?

  • If you used to be able to run python script.py | cprog, then cprog was reading from stdin. Why is this no longer a valid solution for you?
    – Useless
    Oct 15, 2018 at 15:05

1 Answer 1


I suspect you’re looking for

myprogram "$(python x.py)"

This will take the script’s output and use it as the first argument to myprogram (argv[1]).

To use the contents of a file as the first argument to myprogram, cat the file instead:

myprogram "$(cat file)"
  • And how can i use a text file as an input? pipe doesn't work Oct 14, 2018 at 15:19
  • You want to have the contents of a text file in argv[1], is that right? Oct 14, 2018 at 15:39
  • That is correct Oct 14, 2018 at 18:32
  • See the update. Oct 15, 2018 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .