exec - Unix

This is a discussion on exec - Unix ; I am using exec in following way. execl("/usr/bin/cksum","/usr/bin/cksum",rfile,(char*)NULL)) But I want too store the ouput in some file. for eg : cksum filename > tempfile How can write output in somw using exec?...

+ Reply to Thread
Results 1 to 2 of 2

Thread: exec

  1. exec

    I am using exec in following way.



    execl("/usr/bin/cksum","/usr/bin/cksum",rfile,(char*)NULL))



    But I want too store the ouput in some file.

    for eg : cksum filename > tempfile

    How can write output in somw using exec?


  2. Re: exec

    On 27 Oct 2005 20:46:12 -0700, friend.05@gmail.com wrote:
    > I am using exec in following way.
    >
    >
    >
    > execl("/usr/bin/cksum","/usr/bin/cksum",rfile,(char*)NULL))
    >
    >
    >
    > But I want too store the ouput in some file.
    >
    > for eg : cksum filename > tempfile
    >
    > How can write output in somw using exec?


    fd = open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, 0644);
    if (fd < 0) {
    perror("open");
    exit(1);
    }
    if (fd != STDOUT_FILENO) {
    dup2(fd, STDOUT_FILENO);
    close(fd);
    }
    execl("/usr/bin/cksum","/usr/bin/cksum",rfile,(char*)NULL))
    perror("execl");
    exit(127);

    (you may want to replace exit with _exit if in a child process).

    --
    Stephane

+ Reply to Thread