Code Comments
Programming Forum and web based access to our favorite programming groups.Hi I have a program which makes a system call as below: <snip> $run_this_first = "adfind -b dc=co,dc=umist,dc=ac,dc=uk -h $ARGV[0] -f (cn=$ARGV[2])"; system $run_this_first ; </snip> This sends a stream of output to the stdio (screen) How can I redirect this to a file ? I have a similar section called run_this_second which need to be sent to a different file so I cannot simply >> the whole output I have opened a file for writing open (FIRST,">e:/ad_stuff/first_file"); And I can write to this with : print FIRST "hello world to first"; But I cannot get the system call to write to this file ! Any suggestions ? TIA Paul
Post Follow-up to this messagePaul Johnston wrote:
> system $run_this_first ;
>
> This sends a stream of output to the stdio (screen)
> How can I redirect this to a file ?
You need to learn two things.
1) The system() function accepts Bourne Shell (/bin/sh) syntax.
2) Use backticks (`` or qx{}) to grab output from a program.
system "$run_this_first >output_file";
or
$_ = `$run_this_first`; print FILE $_;
-Joe
Post Follow-up to this messagePaul Johnston wrote: > Hi > I have a program which makes a system call as below: > > <snip> > $run_this_first = "adfind -b dc=co,dc=umist,dc=ac,dc=uk -h $ARGV[0] -f > (cn=$ARGV[2])"; > system $run_this_first ; > </snip> > > > This sends a stream of output to the stdio (screen) > How can I redirect this to a file ? > I have a similar section called run_this_second which need to be sent > to a different file so I cannot simply >> the whole output > > I have opened a file for writing > open (FIRST,">e:/ad_stuff/first_file"); > And I can write to this with : > print FIRST "hello world to first"; > > But I cannot get the system call to write to this file ! > > > Any suggestions ? > > TIA Paul print FIRST $_ foreach `$run_this_first`; Eric
Post Follow-up to this messageEric Teuber wrote:
> Paul Johnston wrote:
>
>
>
> print FIRST $_ foreach `$run_this_first`;
>
> Eric
and even shorter
not tested:
foreach $i ("first", "second") { print uc($i) $_ foreach `run_this_$i`};
Eric
Post Follow-up to this messageEric Teuber wrote:
> Paul Johnston wrote:
>
>
>
> print FIRST $_ foreach `$run_this_first`;
>
> Eric
and even shorter if you want to redirect both system calls to different
logfiles.
not tested:
foreach $i ("first", "second") { print uc($i) $_ foreach `$run_this_$i`};
Eric
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.