Professional Web Applications Themes

How to redirect stdout to a file with fork-exec? - UNIX Programming

Greetings, I writing a fork-exec program as: if ((pid = fork()) == 0) { // Question here: how a redirect exec-ing process's output to a file? exec(); } else if (pid > 0) { // Wait for exec-ed process terminated. // Then read the output file. } Thanks in advance! Evan...

  1. #1

    Default How to redirect stdout to a file with fork-exec?

    Greetings,

    I writing a fork-exec program as:

    if ((pid = fork()) == 0)
    {
    // Question here: how a redirect exec-ing process's output to a file?

    exec();
    }
    else if (pid > 0)
    {
    // Wait for exec-ed process terminated.
    // Then read the output file.
    }

    Thanks in advance!
    Evan


    music4 Guest

  2. #2

    Default Re: How to redirect stdout to a file with fork-exec?

    In article <bkmf2p$proxy.lucent.com>, music4 wrote: 
    int fd = open("filename",yourflags);
    dup2(fd,STDOUT_FILENO);
    cloes(fd);

    If I remember correctly.. Probably you can use 2 instead of STDOUT_FILENO.
     


    --
    Vennlig hilsen/Best Regards
    Nils Olav Selåsdal <NOS at Utel.no>
    System Engineer
    UtelSystems a/s

    Nils Guest

  3. #3

    Default Re: How to redirect stdout to a file with fork-exec?

    In article <dyndns.org>,
    Nils O. Selåsdal <no> wrote: 
    > int fd = open("filename",yourflags);
    > dup2(fd,STDOUT_FILENO);
    > cloes(fd);
    >
    >If I remember correctly.. Probably you can use 2 instead of STDOUT_FILENO.[/ref]

    That wouldn't be a good idea, since 2 is stderr, not stdout.

    --
    Barry Margolin, com
    Level(3), Woburn, MA
    *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
    Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
    Barry Guest

Similar Threads

  1. Redirect stdout, stderr to file and stdout
    By Larry Guest in forum PERL Beginners
    Replies: 8
    Last Post: January 20th, 10:42 AM
  2. redirect stdout
    By T. Onoma in forum Ruby
    Replies: 10
    Last Post: November 28th, 07:31 AM
  3. OO file handle for stdout
    By Eric J. Roode in forum PERL Miscellaneous
    Replies: 2
    Last Post: August 5th, 02:50 AM
  4. Replies: 4
    Last Post: June 30th, 11:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139