# программа, моделирующая команду Shell

**URL:** <http://linux.ru/forum/t/shell/10231>\
**Category:** Программирование: C / C++\
**Created:** [13.Апрель.2014 17:41:30 UTC](http://linux.ru/forum/t/shell/10231 "2014-04-13T17:41:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Poul](http://linux.ru/forum/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Poul](http://linux.ru/forum/u/Poul)\
**Post date:** [13.Апрель.2014 17:41:30 UTC](http://linux.ru/forum/t/shell/10231/1 "2014-04-13T17:41:30Z")

</div>

Добрый вечер. Не могу решить задачу, может кто подскажет в чем ошибка?

\_ **./pr1\<f.dat\>f.rez** \_

&nbsp;

#include \<sys/types.h\>  
#include \<sys/stat.h\>  
#include \<sys/wait.h\>  
#include \<unistd.h\>  
#include \<stdio.h\>  
#include \<fcntl.h\>  
#include \<stddef.h\>  
#include \<stdlib.h\>  
#include \<errno.h\>

int main(int argc, char \*argv) {  
&nbsp; printf(“Число переданных параметров программе %s = %d\n”, argv[0], argc);  
&nbsp; int p = fork();  
&nbsp; if (p == -1) {  
&nbsp;&nbsp;&nbsp; perror(“error fork”);  
&nbsp;&nbsp;&nbsp; exit(1);  
&nbsp; } else if (p == 0) {  
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp;&nbsp; int fdr = open(argv[2], O\_WRONLY); &nbsp;  
&nbsp;&nbsp;&nbsp; if (fdr == -1) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror(“error file for read”);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(2);  
&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; dup2(fdr, 1);  
&nbsp;&nbsp;&nbsp; close(fdr);  
&nbsp;&nbsp;&nbsp; execlp(“argv[0]”, “argv[0]”, “argv[1]”, NULL);  
&nbsp;&nbsp; &nbsp;  
&nbsp; } else {  
&nbsp;&nbsp;&nbsp; wait(NULL);  
&nbsp;&nbsp;&nbsp; /\*int fdw = open(argv[2], O\_WRONLY | O\_CREAT, 0666);  
&nbsp;&nbsp;&nbsp; if (fdw == -1) {  
&nbsp;&nbsp; &nbsp;perror(“error file for write”);  
&nbsp;&nbsp; &nbsp;exit(3);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; dup2(fdw, 1);  
&nbsp;&nbsp;&nbsp; close(fdw);  
&nbsp;&nbsp;&nbsp; execl(“argv[1]”, “argv[1]”, “argv[2]”, NULL);  
&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp;&nbsp; perror(“error”);  
&nbsp;&nbsp;&nbsp; exit(4);\*/  
&nbsp; }  
&nbsp; return 0;  
}

---

<div class="post-metadata">

**Author:** ![Firebird](http://linux.ru/forum/letter_avatar_proxy/v4/letter/f/2acd7d/32.png) [@Firebird](http://linux.ru/forum/u/Firebird)\
**Post date:** [13.Апрель.2014 18:00:38 UTC](http://linux.ru/forum/t/shell/10231/2 "2014-04-13T18:00:38Z")

</div>

А что задача делать должна-то? И в чем вернее конкретно вопрос?
