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

Use the -t test for STDIN

perl -le'print "\e]0;$ENV{HOST}\7" if -t'
print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

Replies are listed 'Best First'.
Re^4: system function adds spurious characters to log file
by Anonymous Monk on Sep 07, 2009 at 14:54 UTC
    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'

      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)))

      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)))
      okay, if I'm logged in, the PerlMonks bar is red or red-ish otherwise it's blue