redirecting output from one perl script to a file (withough changing the perl script itself) 
Author Message
 redirecting output from one perl script to a file (withough changing the perl script itself)

Dear all,

I have a perl program that I have been using. it basically prints some
output to screen. What I want to do is be abel to redirect this output a
(text) file. I have tried running the command from NT (v4 srvpck 5)
command line which only produces a blank file.

i.e. perl.exe perlscript.pl (input parameter) > output.txt

Can anyone provide a quick fix? I would be very grateful for any help.
Thanking you in advance and for your kind attention,

Kourosh A Mojar



Wed, 18 Jun 1902 08:00:00 GMT  
 redirecting output from one perl script to a file (withough changing the perl script itself)

Quote:

>Dear all,

>I have a perl program that I have been using. it basically prints some
>output to screen. What I want to do is be abel to redirect this output a
>(text) file. I have tried running the command from NT (v4 srvpck 5)
>command line which only produces a blank file.

>i.e. perl.exe perlscript.pl (input parameter) > output.txt

>Can anyone provide a quick fix? I would be very grateful for any help.
>Thanking you in advance and for your kind attention,

the redirection with > should work, but since it doesnt ....

you might want to try to create a file-handle like this:

        open(FILE, "> output.txt");

and then substitute every line that contains a print-statmenet with something
like this:

        print FILE ("blablabla");

don't forget to put a

        close(FILE);

at the end of your program ...

        good luck !

                Bas

--

http://stuwww.kub.nl/people/b.vangils                  || language of
System Administrator of http://stuwww.kub.nl/          || complicity



Wed, 18 Jun 1902 08:00:00 GMT  
 redirecting output from one perl script to a file (withough changing the perl script itself)

Thank you for you reply. I though that would be a straightforward
solution. But the the code I have been using is made up of all sorts of
strings and printf statements that I don't understand.

Is it possible to execute a perl script within another script and
capture the output? Any other solutions?

Regards,

Kourosh A Mojar

Quote:


> >Dear all,

> >I have a perl program that I have been using. it basically prints some
> >output to screen. What I want to do is be abel to redirect this output a
> >(text) file. I have tried running the command from NT (v4 srvpck 5)
> >command line which only produces a blank file.

> >i.e. perl.exe perlscript.pl (input parameter) > output.txt

> >Can anyone provide a quick fix? I would be very grateful for any help.
> >Thanking you in advance and for your kind attention,

> the redirection with > should work, but since it doesnt ....

> you might want to try to create a file-handle like this:

>         open(FILE, "> output.txt");

> and then substitute every line that contains a print-statmenet with something
> like this:

>         print FILE ("blablabla");

> don't forget to put a

>         close(FILE);

> at the end of your program ...

>         good luck !

>                 Bas

> --

> http://stuwww.kub.nl/people/b.vangils                  || language of
> System Administrator of http://stuwww.kub.nl/          || complicity



Wed, 18 Jun 1902 08:00:00 GMT  
 redirecting output from one perl script to a file (withough changing the perl script itself)

Quote:

> How to call a perl script from another perl script?

Short answer: use the "do" statement.

This question was just asked a few days ago on perl-win32-web.  I've
included a (slightly edited) copy of the answer that I gave there.

--Bill

-----

You can use the system() function, or enclose a command in `backticks`,
to
run another copy of the perl interpreter with a different script.  As
far as
the current perl script is concerned, you're just running some new
program.
However, I prefer to use the "do" statement.  Here's what it says in
perlfunc:

   do EXPR

   Uses the value of EXPR as a filename and executes
   the contents of the file as a Perl script.

   [...]

   If do cannot read the file, it returns undef and
   sets $! to the error. If do can read the file but
   cannot compile it, it returns undef and sets an

   compiled, do returns the value of the last
   expression evaluated.

...and so on and so forth.  One drawback: passing arguments to the
called
script takes a little work.  I do it with this subroutine:

   use Carp;

   sub plrun
     {
       my $script = shift;

       unless (-e $script)
         {
           carp "'$script' not found";
           return 0;
         }


       do $script;
     }

   __END__


parameters of

restored
to its value prior to calling plrun().  Use it like this:

   plrun("my_perl_script.pl", "somefile.txt", "another arg");


just
like running a perl script from the command prompt.

--Bill Odom



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. how do I redirect the output of an existing perl script

2. Including my perl functions in one file in another perl script file

3. Redirect STDOUT from a Unix script to a perl program and then redirect back to script

4. How to redirect output within Perl script?

5. how do I redirect the output of an existing perl script

6. Redirecting output in a Perl script

7. redirecting output changes order?

8. changing the output file for every script run

9. Getting a script output one line at a time before the script ends executing

10. Out of Office AutoReply: Deja.Com Daily Digest: comp.lang.perl.mi sc 2/4

11. Searching for cgi-script for redirect from one domain to a co-domian

12. Redirecting Error Output for Non-CGI Script

 

 
Powered by phpBB® Forum Software