Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Command Bash中特定命令的协助_Command - Fatal编程技术网

Command Bash中特定命令的协助

Command Bash中特定命令的协助,command,Command,我有一个用c写的程序 argv[0]=command; argv[1]=NULL; if(strcmp(command,"ls > try.txt")) { dup2(fd,1); close(fd); execvp(command,argv); perror("execvp"); exit(1); } execvp(command,argv); perror("execvp"); exit(1); 我想要:如果我写ls>try.txt

我有一个用c写的程序

argv[0]=command;
argv[1]=NULL;

if(strcmp(command,"ls > try.txt")) {
     dup2(fd,1);
     close(fd);
     execvp(command,argv);
     perror("execvp");
     exit(1);
}
execvp(command,argv);
perror("execvp");
exit(1);

我想要:如果我写ls>try.txt,只有这个命令有效

试着用引号括起这个命令,比如:
/a.out'ls>try.txt'
问题是,如果我在Bash ls中输入文本,它不会显示输出。我想如果我发短信ls>try.txt,然后只在这种情况下将输出放入try.txt,如果我发短信给任何其他命令只是为了告诉我它的输出,你有什么想法吗?恐怕我不明白:-(