[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] setting in MacPerl IDE to redirect output?




On Tue, 30 Nov 1999, Chris Nandor wrote:
> Make a module file "STDOUT.pm" and put it in your site_perl, containing:
> 
>    package STDOUT;
>    open STDOUT, ">>foo" or die $!;
> 
> The go to Preferences -> Environment and add an environment var named
> "PERL5OPT" with the value "-MSTDOUT".  Done!


Okay, confessional time...I tried to get a little tricky.  I made a file
called Redirect.pm in site_perl:Mac, which looks like this:


package Mac::Redirect;

use Mac::StandardFile;

my @parts = split(/:/, $0);
my $name = substr( pop( @parts), 0, 26); 
$file = StandardPutFile('Redirect stdout to', "$name.out");

if ($file->sfGood()) 
{   
    open SAVEOUT, ">&STDOUT" or die "Could not dup STDOUT: $!\n";
    open STDOUT, "> $file->sfFile()" or die "File redirect failed: $!";
    $|=1;   
} 
else 
{   die "Could not redirect output!\n";   }


END 
{
   open STDOUT, ">&SAVEOUT"  if defined( SAVEOUT); 
   $|=0;
}


My PERL5OPT is -MMac::Redirect.  The problem is the script dies after the
StdPutDialog, saying 

     File redirect failed: File name too long.

The file name shown on the StdPutDlg was only 14 chars long, including the
".out" extension.  I clicked beyond the end of the word; if there were any
invisible characters, they had zero length.  I s'pose ->sfFile() is
returning the full path and name.  What do I need to do to get Perl to
handle it?

The rest of the name gyrations, BTW, seemed to work: only the
filename.out was shown, not the path.  I didn't really care enough about
pre-existing extensions to try removing them--filename.plx.out would be
fine with me.

Can anyone spot my boo-boo(s) and make it(them) better?


Let me add that I've tried inserting a line between the two opens:

       ($fh = new FileHandle( $file->sfFile()) ) or die "new FileHandle
failed: $!";;

(of course I also added the "use FileHandle", too).  When I do this, the
dying error becomes 

    new FileHandle failed: No such file or directory.



--
MattLangford 




# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org