[Prev][Next][Index][Thread]

Re: fork & exec.



Asaf Sabag wrote:
> Maybe I did not make my self clear,

Yes, that's what I suspected from reading someone else's response.

> 
> When I do exec for /bin/tar the tar command is found and exec execute the tar.

So your problem is not with exec.  You should either wait for tar's
process to exit (in the parent) and look at its exit status, or
forward tar's output to a pipe and parse it.

> 
> For example:
> ------------
> 
> if (pid = fork() == 0) {
>  execid = execl("/bin/tar", "tar", "cvf", "/dev/fdo", 0)
>  perror("exec failed");
> }
> printf("exec passed\n");

You don't handle the case of fork()==-1 (fork fails, could happen).

> 
> the exec execute the tar and the exec passes OK.
> No error is printed.
> the massage : "exec passed" comes.
> 
> The problem is that if there is no disk in the drive or if there is no tar
> file in it then the tar failes!
> 
> This leads to no error from exec! beacuse exec passed.

Again, at the stage that tar finds that there is no disk, the exec(2)
system call is allready finished.

> and the massage "exec passed" comes,
> 
> If I use the system command and tar failes I get an error masaage from tar.
> 
> For example:
> ------------
> 
> if (i = system("/bin/tar xvf /dev/fd0 > /tmp/TarList.txt") == 0)
>   XtManageChild(SysToolOBJ.DialogGoodExpand_ExpandDevice);
> else
>  XtManageChild(SysToolOBJ.ErrorMsgExpandFailed_ExpandDevice);
> 
> I want to execute the same command with exec not system.
> But I don't get the error massage from tar within exec.
> 
> HOW can I make it work with exec???

Just read Stevens, it should clarify this.

--Amos

--Amos Shapira                   | "Of course Australia was marked for
133 Shlomo Ben-Yosef st.         |  glory, for its people had been
chosen
Jerusalem 93 805                 |  by the finest judges in England."
ISRAEL            amos@dsi.co.il |                     -- Anonymous


References: