How to redirect console output to a text file

后端 未结 4 2042
眼角桃花
眼角桃花 2020-12-31 17:15

I am executing a Perl program. Whatever is being printed on my console, I want to redirect that to a text file.

4条回答
  •  既然无缘
    2020-12-31 17:34

    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)

    open (STDOUT, "| tee -ai logs.txt");
    print "It Works!";
    

    After last print in your script

    close (STDOUT);
    

    For error messages only,

    open (STDERR, "| tee -ai errorlogs.txt");
    

提交回复
热议问题