Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script running on HP-UX, it tars and gzips up files so I run each the commands in the background. Only trouble is the commands add spurious characters to the log file. I looked around for a day to try to fix this but no luck. here is the perl code
foreach $tar_star_list (@tar_star_list) { $complete_zip_spec = $output_path . "/" . $tar +_star_list . ".tgz"; print "\$tar_star_list $tar_star_list \n"; system ("tar -cvf - $tar_star_list.* | gzip > +$complete_zip_spec &"); }
and here are the spurious characters
$tar_star_list civil ^[]0;saturnn2^G $tar_star_list eco ^[]0;saturnn2^G $tar_star_list slc ^[]0;saturnn2^G
saturnn2 is the hostname. How can I get rid of the ^[]0;saturnn2^G string?

Replies are listed 'Best First'.
Re: system function adds spurious characters to log file
by ikegami (Patriarch) on Sep 04, 2009 at 19:27 UTC
    Sounds like a broken shell config. Does sh -c exit output the host name? The weird characters are likely terminal control characters.
Re: system function adds spurious characters to log file
by bv (Friar) on Sep 04, 2009 at 19:55 UTC

    According to my man page for console_codes, it's trying to set your window title to saturnn2 and ringing the system bell. Probably your shell is being a little too "full featured." You could try to force a particular shell to handle it, something like:

    system ('/bin/sh', '-c', "tar -cvf - $tar_star_list.* | gzip > $complete_zip_spec &");

    Note that by using system in list context, you avoid using whatever shell Perl usually uses. Then you can find the right set of arguments to your shell of choice that will produce the desired output.

    Of course, you could do all the forking and piping and redirection in pure Perl, but that may be more coding than you want to get into.

    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
      bv you are a genius! I was setting the window title on saturnn2 with
      #perl -le'print "\e]0;$ENV{HOST}\7"'
      I commented it out and it fixed the problem! Thanks How can I get the set the title only for interactive sessions and not for other processes?

        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)))
Re: system function adds spurious characters to log file
by Perlbotics (Archbishop) on Sep 04, 2009 at 19:32 UTC

    The first part looks like an ANSI control sequence. Maybe you have something like that in a shell related resource file that outputs this character sequence? Is there a wrapper or alias for tar in place?
    Have a look at /etc/profile, ~/.profile, ~/.bashrc, ~/.cshrc, and the like. The $MAIL* environment variables are another potential cause of this problem.

    Alternatively - more perlish - you could try to bypass the indirect shell invocation by using system in list contextwith an argument list. E.g., tar might support compression using switches like -j/-z/-Z (get rid of gzip invocation). See fork to run the command as a background process.
    HTH