我正在写一个C程序,它决定从标准输入读取的字节数。我 发现有办法让输入到程序linux找到调用的命令
- 管道输入
- 重定向
- 进入命令行,而程序正在等待输入
如何找到确切从shell执行程序的命令。 我尝试使用命令行参数,但失败。
#include <stdio.h>
int main(int argc,char *argv[])
{
char buffer[100];
int n;
for(n=1;n<argc;n++)
printf("argument: %s\t",argv[n]);
printf("\n");
if(argc==1)
printf("waiting for input :");
else if (argc==3)
printf("Not waiting for input . Got the source from command itself .");
n = read(0,buffer,100);
if(n==-1)
printf("\nError occured in reading");
printf("\nReading successfully done\n");
return 0;
}
此外,
你忘了在'read'之前调用fflush' –
目前还不清楚你是否要计算你的程序或其他程序读取的字节数...... –