in reply to Re^3: system function adds spurious characters to log file
in thread system function adds spurious characters to log file

em bv I justed tested the if -t and it doesn't work, I got the messages in my log file here is the code a I used with a comment added
# perl -le'print "\e]0;$ENV{HOST}\7" if -t'

Replies are listed 'Best First'.
Re^5: system function adds spurious characters to log file
by bv (Friar) on Sep 07, 2009 at 17:38 UTC

    The -t test checks if STDIN is coming from a tty or not, similar to POSIX::isatty. When you invoke your shell script automatically, redirect STDIN from /dev/null. Like this:

    $ cat test.sh #!/bin/sh perl -le 'print "Interactive" if -t' perl -le 'print "Batch" unless -t' $ sh test.sh Interactive $ sh test.sh </dev/null Batch
    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
Re^5: system function adds spurious characters to log file
by bv (Friar) on Sep 08, 2009 at 13:53 UTC

    I hope you're still following this thread, because I just realized a better way: Test STDOUT, not STDIN. You don't care where the input is coming from, but whether you are outputting to the screen or to a file.

    $ cat works.sh #!/bin/sh perl -le 'print "Screen" if -t STDOUT' perl -le 'print "File" unless -t STDOUT' $ sh works.sh Screen $ sh works.sh > out.txt $ cat out.txt File
    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
Re^5: system function adds spurious characters to log file
by 45north (Initiate) on Sep 07, 2009 at 15:02 UTC
    okay, if I'm logged in, the PerlMonks bar is red or red-ish otherwise it's blue