Find the answer to your Linux question:
Results 1 to 5 of 5
Is there a way to capture all the stdout being generated? I am running a series of bash/perl scripts that all spawn off child processes, aside from piping every system ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    3

    stdout

    Is there a way to capture all the stdout being generated? I am running a series of bash/perl scripts that all spawn off child processes, aside from piping every system call to a log file, is there anyway to capture all the stdout all of these processes output?

    Thanks

  2. #2
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Hi, how about grouping them together in a subshell or a script and redirecting the entire the subshell/script??
    Code:
    (echo Alice; echo has; echo a; echo cat) > /tmp/file.txt
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  3. #3
    Just Joined!
    Join Date
    Aug 2007
    Posts
    3
    Hi, how about grouping them together in a subshell or a script and redirecting the entire the subshell/script??
    Code:
    (echo Alice; echo has; echo a; echo cat) > /tmp/file.txt
    I don't believe that will work, as the sub processes are all kicked off at different times during the script.

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    A process inherits its stdout from its parent. So if I redirect the stdout of the original script, all of its children will have their stdout redirected as well.

    EDIT:

    An example:
    Code:
    alex@danu ~/test/c $ cat stdout_redirect.c 
    #include <stdio.h>
    #include <sys/types.h>
    #include <unistd.h>
    
    int main()
    {
            pid_t cid;
    
            cid = fork();
            puts("Both processes should print this");
            if(cid == 0)
            {
                    puts("Only the child should print this");
                    return 0;
            }
    
            puts("Only the parent should print this");
    
            return 0;
    }
    alex@danu ~/test/c $ gcc -Wall stdout_redirect.c 
    alex@danu ~/test/c $ ./a.out > redirected_output
    alex@danu ~/test/c $ cat redirected_output 
    Both processes should print this
    Only the child should print this
    Both processes should print this
    Only the parent should print this
    Note how even the child process prints to the redirected stdout
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    Just Joined!
    Join Date
    Aug 2007
    Posts
    3
    Thanks, I thought I had tried that, but apparently not..

    That worked.

Posting Permissions

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