Re-directing system call
am 28.04.2005 12:26:53 von Paul Johnston
Hi
I have a program which makes a system call as below:
$run_this_first = "adfind -b dc=co,dc=umist,dc=ac,dc=uk -h $ARGV[0] -f
(cn=$ARGV[2])";
system $run_this_first ;
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
Re: Re-directing system call
am 28.04.2005 21:17:27 von Joe Smith
Paul 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
Re: Re-directing system call
am 28.04.2005 23:52:14 von Eric Teuber
Paul Johnston wrote:
> Hi
> I have a program which makes a system call as below:
>
>
> $run_this_first = "adfind -b dc=co,dc=umist,dc=ac,dc=uk -h $ARGV[0] -f
> (cn=$ARGV[2])";
> system $run_this_first ;
>
>
>
> 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
Re: Re-directing system call
am 29.04.2005 00:13:22 von Eric Teuber
Eric Teuber wrote:
> Paul Johnston wrote:
>
>> Hi
>> I have a program which makes a system call as below:
>>
>>
>> $run_this_first = "adfind -b dc=co,dc=umist,dc=ac,dc=uk -h $ARGV[0] -f
>> (cn=$ARGV[2])";
>> system $run_this_first ;
>>
>>
>>
>> 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
and even shorter
not tested:
foreach $i ("first", "second") { print uc($i) $_ foreach `run_this_$i`};
Eric
Re: Re-directing system call
am 29.04.2005 00:27:53 von Eric Teuber
Eric Teuber wrote:
> Paul Johnston wrote:
>
>> Hi
>> I have a program which makes a system call as below:
>>
>>
>> $run_this_first = "adfind -b dc=co,dc=umist,dc=ac,dc=uk -h $ARGV[0] -f
>> (cn=$ARGV[2])";
>> system $run_this_first ;
>>
>>
>>
>> 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
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