Hi David,
> I would like to redirect standard output generated by
p4perl commands to
> some predefined log files. Normally, when using plain
vanilla perl (but
> not p4perl), I would do something like this:-
>
>
>
> open( SYNCLOG, ">mySync.log" );
>
> open( SYNC, "p4 sync -f //... | " );
>
> while (<SYNC>) {
>
> print SYNCLOG $_:
>
> }
>
> close SYNCLOG;
If you just want the output to go to a file, why not just
use:
system( "p4 sync -f //... > mySync.log" );
Is there a specific reason you want to use P4Perl? I'm not
trying to put you
off, but in the example you've given, using P4Perl doesn't
buy you much. It's
more useful if you want to parse the results of Perforce
commands in your
scripts in a structured way.
> I have not been able to figure out how to adapt the
above to redirect
> the standard output to a log file. I tried using the
"select" command,
> this time during the creation of a new p4 client, but
it does not seem
> to work:-
>
>
>
> open( P4CLIENT_LOG, ">p4client.log" );
>
> my $initial_fh = select( P4CLIENT_LOG );
>
> ...
>
> <steps to set up for the creation of a new p4
client>
>
> ...
>
> $p4->SaveClient( $clientSpecs, "-f" );
>
> $p4->SetInput( $clientSpecs );
>
> $p4->Run( "client", "-i" );
>
> close( P4CLIENT_LOG );
>
> select( $initial_fh );
>
>
>
> Output from this continues to go to the standard output
instead of the
> predefined p4client.log file.
I'm surprised to hear that you get any output at all.
P4Perl returns its
output in an array variable, and since your sample code
above doesn't use the
return value, I can't see how you get any output anywhere.
Very odd.
> Any suggestions?
This should do the trick:
foreach my $out ( {$p4->Sync( "-f",
"//..." )} )
{
print( P4CLIENT_LOG $out, "\n" );
}
You can also write errors and warnings to the logfile by
calling $p4->Errors()
and $p4->Warnings().
Regards,
Tony
_______________________________________________
p4perl mailing list
p4perl perforce.com
http://maillist.perforce.com/mailman/listinfo/p4perl
|