I am executing a Perl program. Whatever is being printed on my console, I want to redirect that to a text file.
相关问题
- $ENV{$variable} in perl
- Is it possible to pass command-line arguments to @
- softlinks atime and mtime modification
- Redirecting STDOUT and STDERR to a file, except fo
- Change first key of multi-dimensional Hash in perl
相关文章
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Compile and build with single command line Java (L
- Can NOT List directory including space using Perl
- Extracting columns from text file using Perl one-l
- Lazy (ungreedy) matching multiple groups using reg
- How do I tell DBD::mysql where mysql.sock is?
- How to update command line output?
If you want your output to be printed on console as well as logs then append this line to you code (e.g. before any print statements)
After last print in your script
For error messages only,
The preferred method for this is to handle redirection via the command line, e.g.
If you want to also include stderr output then you can do this (assuming your shell is bash):
On Unix, to capture everything that goes to your terminal, you want to redirect both the standard output and the standard error.
With bash, the command resembles
The C shell,
csh
derivatives such astcsh
, and newer versions of bash understandto mean the same thing.
The syntax for the command shell on Windows resembles Bourne shell's.
To set up this redirection in your Perl code, add
to the beginning of your program’s executable statements.
In the CLI you can use
>
, like this:If you want to do this inside the perl script, add this code before you print anything: