Is Morningtide out yet? Guess not.

For long running processes like that, I usually tee the output. And since Windows doesn't have tee, I wrote one quickly.

tee.bat:

@rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT perl -x -S %0 %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo You do not have Perl in your PATH. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul goto endofperl @rem '; #!perl #line 15 use strict; use warnings; use IO::Handle qw( ); use Getopt::Long qw( ); my $opt_a; sub usage { print STDERR (<<'__EOI__'); usage: tee [<options>] [--] [file [...]] Use tee --help for help. __EOI__ exit(1); } sub help { print(<<'__EOI__'); usage: tee [<options>] [--] [file [...]] Use tee --help for help. Options: -a Append the output to the files rather than overwriting them. -i Ignore the SIGINT signal. __EOI__ exit(0); } sub process_args { Getopt::Long::Configure('posix_default'); Getopt::Long::GetOptions( "a" => \$opt_a, "help|h|?" => \&help, ) or usage(); } { process_args(); my $mode = ($opt_a ? '>>' : '>' ); my $mode_text = ($opt_a ? 'open' : 'create'); my @fhs; my %fh_names; { my $fh = \*STDOUT; push @fhs, $fh; $fh_names{$fh} = 'STDOUT'; } foreach (@ARGV) { my $fh; if (!open($fh, $mode, $_)) { die("Unable to open file \"$_\": $!\n"); } push @fhs, $fh; $fh_names{$fh} = "file \"$_\""; } binmode(STDIN); foreach my $fh (@fhs) { $fh->autoflush(1); binmode($fh); } for (;;) { my $buf = ''; my $rv = sysread(STDIN, $buf, 4096); if (not defined $rv) { die("Unable to read from STDIN: $!\n"); } if (not $rv) { last; } foreach my $fh (@fhs) { if (!$fh->print($buf)) { die("Unable to write to $fh_names{$fh}: $!\n"); } } } } __END__ :endofperl

In reply to Re^3: Can't write files (even redirected from shell) by ikegami
in thread Can't write files (even redirected from shell) by Flame

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.