0

I have a simple C program that prints out argc:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
    printf("argc = %d\n", argc);
    return 0;
}

I'm trying to test it with inputs given by python commands in the command line, but I get the following error:

C:\Users...\bin\Debug>python -c "print('A')" | pwnable.exe
argc = 1
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
OSError: [Errno 22] Invalid argument

prints out 1 instead of 2.

Why does this error appear, and what does it mean?

Yonatan H
  • 43
  • 1
  • 9

1 Answers1

0

Piping writes to standard input, not command line arguments. If you want the output to be an argument, use command substitution.

pwnable.exe "$(python -c "print('A')")"

Error 22 seems to be something specific to printing to a pipe on Windows, see this similar question: Python print and wc with invalid argument leads to OSError

Barmar
  • 741,623
  • 53
  • 500
  • 612