C 为什么可以';我不能打印传递给程序的第一个参数吗?
我用c编写了一个简单的代码:C 为什么可以';我不能打印传递给程序的第一个参数吗?,c,bash,arguments,C,Bash,Arguments,我用c编写了一个简单的代码: #include <stdio.h> int main( int argc, char* argv[] ) { printf( "Hello, just wanted to say: %s.\n", argv[1] ); return 0; } 放入%s的输出是(null),而不是预期的“Hello”。为什么?你似乎误解了管道的工作原理。当您像以前那样使用管道时,app1的输出用作app2的stdin,而不是app2的命令行参数 是这样
#include <stdio.h>
int main( int argc, char* argv[] ) {
printf( "Hello, just wanted to say: %s.\n", argv[1] );
return 0;
}
放入
%s
的输出是(null)
,而不是预期的“Hello”。为什么?你似乎误解了管道的工作原理。当您像以前那样使用管道时,app1
的输出用作app2
的stdin
,而不是app2
的命令行参数
是这样的:
stdin->app1->stdout >----------> stdin->app2->stdout
pipe
您看到的是
/app2
的输出/app1
的输出与示例命令无关
stdin->app1->stdout >----------> stdin->app2->stdout
pipe