in reply to Re: Test whether STDOUT is connected to a file
in thread Test whether STDOUT is connected to a file

If the first argument to system is 1, it creates a process in the background. Unfortnately, this is not documented in system. See perlport for the details.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^3: Test whether STDOUT is connected to a file
by JavaFan (Canon) on Aug 18, 2010 at 14:35 UTC
    Indeed, so it does. I checked perlport before writing my post, but somehow, I manage to miss this. It does, however, say system(1, @args), not system(1, [@args]). And I assume it's equivalent to system(@args), which, as I said, results in calling perl.exe with three arguments: myProg.pl, >out.txt, and 2>&1. Try this instead: system(1, "perl.exe myProg.pl >out.txt 2>&1") or system("perl.exe myProg.pl >out.txt 2>&1 &")
      Try this instead: system(1, "perl.exe myProg.pl >out.txt 2>&1") or system("perl.exe myProg.pl >out.txt 2>&1 &")
      Though this would work, it would create an intermediary CMD.EXE process, and this is something I want to avoid. This is related to the issues discussed in waitpid returns -1 for still running child - I didn't mention this to not complicate things further.

      I now use the workaround of having the called process check whether it is still connected to a terminal, and if it is, redirect STDOUT. The solution is not really satisfying, because it opens up its own problems, but for the time being it works. I hope to find something better eventually.

      -- 
      Ronald Fischer <ynnor@mm.st>
        If you want to avoid using cmd.exe, you'll have to do the redirection yourself. You cannot have your cake (make use of the shells redirection capabilities) and eat it (not start a shell).

        You may want to study perlopentut and perlipc.