python -c 'print "A"*1000'
은 A
000 번을 인쇄합니다. 이것을 C 프로그램에 전달하고자한다면, 적어도 하나의 크기가 1000
보다 큰 버퍼가 필요하며, 여분의 1은 널 문자를 수용하는 것입니다.
#include <stdio.h>
#include <string.h> // for strcpy
int main(int agrc, char* argv[])
// int argc- is for number of arguments
// char* argv[] - argument strings separated by spaced
// each argument can be accessed by argv[1],argv[2] & so on
{
char name[1001]="";
// initialize name to null & 1001 for the reason mentioned above
printf("%s\n", name);
// %p specifier is for the pointer,i used %s here for the string
fflush(stdout);
/*
* This part of your code is useless if you wish
* to store the name from the argument.
puts("What's your name?");
fflush(stdout);
gets(name);
*/
strcpy(name,argv[1]); // copying the cmd line argument to name.
printf("Hello, %s!\n", name);
return 0;
}
이제, 당신이 "파이프"를 필요로 다른 명령의 표준 입력으로 한 명령의 표준 출력에서 데이터를 전송하는
$./a.out "$(python -c 'print "A"*1000')"
먼저 주에게 인수를 전달하는 방법을 살펴 보았습니다. –