Afonso
Afonso

Reputation: 77

How to pipe multiple values to a C program, with python -c

So, I know I can pipe a value, with python, to the stdin of a C program:

python -c 'print "Hello"' | ./program

The 'Hello' string will be read by the first scanf of the C program (or similar function).

My problem is, how do I do this when I have multiple scanfs and I want to pass individual values to each one of them?

Thank you!

Upvotes: 1

Views: 140

Answers (1)

Rafik Farhad
Rafik Farhad

Reputation: 1202

In the same manner you can do this. Suppose your C program take a string first and then two integer.

So you separate the input value by \n as you would do in a terminal, like:

python -c 'print "Hello\n5 10"' | ./program

Upvotes: 2

Related Questions