I have a file.c:

#include <stdio.h>
void main(){
        char a,b;
        printf("Input your character: \n");
        printf("Input your second character: \n");
        printf("You char: %c %c\n",a,b);

I use a pipeline to send the first byte 0x01:

python -c "print '\x31'" | ./file

But it can only send one time, I want send: first byte is 0x31 and second byte 0x32, so that the program will print Your char: 1 and 2. How to make it?


You can use multiple print statements in the python command:

python -c 'print "\x31"; print "\x32"' | ./file

Or a single print statement, using a newline:

python -c 'print "\x31\n\x32"' | ./file

Or multiple python commands grouped together before the pipe:

(python -c 'print "\x31"'; python -c 'print "\x31"') | ./file

It seems the characters must not be separated by a newline, in which case:

python -c 'print "\x31\x32"' | ./file
  • It just print You char: 1, I want print You char: 1 2 – QChí Nguyễn Mar 7 '17 at 13:28
  • @QChíNguyễn then it's something wrong with your code. Code debugging questions should be asked on Stack Overflow. – muru Mar 7 '17 at 13:29
  • 1
    @QChíNguyễn on second thought, try python -c 'print "\x31\x32"' | ./file – muru Mar 7 '17 at 13:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.