Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re-directing system call
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

Report this thread to moderator Post Follow-up to this message
Old Post
Paul Johnston
04-28-05 01:56 PM


Re: Re-directing system call
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

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Smith
05-02-05 01:56 AM


Re: Re-directing system call
Paul 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

Report this thread to moderator Post Follow-up to this message
Old Post
Eric Teuber
05-02-05 01:56 AM


Re: Re-directing system call
Eric 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

Report this thread to moderator Post Follow-up to this message
Old Post
Eric Teuber
05-02-05 01:56 AM


Re: Re-directing system call
Eric 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

Report this thread to moderator Post Follow-up to this message
Old Post
Eric Teuber
05-02-05 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:28 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.