i*****8 发帖数: 6735 | 1 熟悉perl的大侠们,
我需要deliver个perl program,user run这个程序的时候有个-logfile option。
可是我想把要print到logfile里的东西在stdout上也显示出来。
simple的方法就是每个msg print两次。
有没有办法只用一次print command,两个地方都有msg了呢? |
i*****8 发帖数: 6735 | 2 我在网上找了找 output redirect, 不大明白啊
【在 i*****8 的大作中提到】 : 熟悉perl的大侠们, : 我需要deliver个perl program,user run这个程序的时候有个-logfile option。 : 可是我想把要print到logfile里的东西在stdout上也显示出来。 : simple的方法就是每个msg print两次。 : 有没有办法只用一次print command,两个地方都有msg了呢?
|
c**e 发帖数: 457 | 3 Try this. It will print to stdout and your-log-file
===========================
#!/usr/bin/perl
open (STDOUT, "| tee -a your-log-file");
print "We love Xiyu!";
close (STDOUT);
===========================
【在 i*****8 的大作中提到】 : 熟悉perl的大侠们, : 我需要deliver个perl program,user run这个程序的时候有个-logfile option。 : 可是我想把要print到logfile里的东西在stdout上也显示出来。 : simple的方法就是每个msg print两次。 : 有没有办法只用一次print command,两个地方都有msg了呢?
|
t*h 发帖数: 1629 | 4 他要反过来,估计事。
现有的程序已经全部print到一个logfile,现在要重新输出出来。要看看
那个logfi
le怎么打开的德,是不是这么把stdout 重订向导file的
【在 c**e 的大作中提到】 : Try this. It will print to stdout and your-log-file : =========================== : #!/usr/bin/perl : open (STDOUT, "| tee -a your-log-file"); : print "We love Xiyu!"; : close (STDOUT); : ===========================
|
g******d 发帖数: 1774 | 5 又读了一下 requirement, 好像cade是对的。
【在 t*h 的大作中提到】 : 他要反过来,估计事。 : 现有的程序已经全部print到一个logfile,现在要重新输出出来。要看看 : 那个logfi : le怎么打开的德,是不是这么把stdout 重订向导file的
|
c**e 发帖数: 457 | 6 为什么有正反先后问题呢,这个程序同时写到stdout和log file啊?
【在 t*h 的大作中提到】 : 他要反过来,估计事。 : 现有的程序已经全部print到一个logfile,现在要重新输出出来。要看看 : 那个logfi : le怎么打开的德,是不是这么把stdout 重订向导file的
|
i*****8 发帖数: 6735 | 7 待我一个个try来。多些诸位答复!
【在 c**e 的大作中提到】 : 为什么有正反先后问题呢,这个程序同时写到stdout和log file啊?
|
d*****d 发帖数: 2449 | 8 like tch said, cade's solution is another way around, instead of copying the
log from the log file to the stdout, it copies stdout to the file. If you
can direct the log to stdout it will work, otherwise it won't.
If you don't need to see the log in the same console, just use "tail -f $LOG
" while $LOG is the name of the log file then you'll see the log output on
the fly. |
d*****d 发帖数: 2449 | 9 又看了一下问题,原来是你要写这个程序,那就无所谓了。 |
c**e 发帖数: 457 | 10 Instead of print the log to the log file handler, just print the log to
stdout in the existing perl program. It should be a very simple change.
For examle,
Change
print LOG-FILE "We love xiyu"
to
print "We love xiyu" to
I do not see whey you can not do that.
the
LOG
【在 d*****d 的大作中提到】 : like tch said, cade's solution is another way around, instead of copying the : log from the log file to the stdout, it copies stdout to the file. If you : can direct the log to stdout it will work, otherwise it won't. : If you don't need to see the log in the same console, just use "tail -f $LOG : " while $LOG is the name of the log file then you'll see the log output on : the fly.
|
|
|
d*****d 发帖数: 2449 | 11
对不起,我错了,我又犯了审题不清的老毛病,我检讨。我以为v8要run一个现成的
perl程序。
【在 c**e 的大作中提到】 : Instead of print the log to the log file handler, just print the log to : stdout in the existing perl program. It should be a very simple change. : For examle, : Change : print LOG-FILE "We love xiyu" : to : print "We love xiyu" to : I do not see whey you can not do that. : : the
|
c**e 发帖数: 457 | 12 I see ur point :)
【在 d*****d 的大作中提到】 : : 对不起,我错了,我又犯了审题不清的老毛病,我检讨。我以为v8要run一个现成的 : perl程序。
|
u****u 发帖数: 2308 | 13 IMHO 你的这个要求是unix programming所忌讳的。dumbird建议的tail -f $logfile才
是王道。
【在 i*****8 的大作中提到】 : 熟悉perl的大侠们, : 我需要deliver个perl program,user run这个程序的时候有个-logfile option。 : 可是我想把要print到logfile里的东西在stdout上也显示出来。 : simple的方法就是每个msg print两次。 : 有没有办法只用一次print command,两个地方都有msg了呢?
|
i*****8 发帖数: 6735 | 14 有啥忌讳?cade的方法好像可行啊。这个tail -f是要user自己干的,是extra的work。
很多时候重要的信息不print到stout上他们不知道要去看log啊
【在 u****u 的大作中提到】 : IMHO 你的这个要求是unix programming所忌讳的。dumbird建议的tail -f $logfile才 : 是王道。
|
t*h 发帖数: 1629 | 15 最简单的就是去掉那个logfile option.如果他们要save 下来,就用重定向。
用 > xxx.log
or | tee xxx.log
前者没有screen output
后者有
【在 i*****8 的大作中提到】 : 有啥忌讳?cade的方法好像可行啊。这个tail -f是要user自己干的,是extra的work。 : 很多时候重要的信息不print到stout上他们不知道要去看log啊
|
i*****8 发帖数: 6735 | 16 去掉logfile option万一出了问题我就无据可查了。。。我还想着偷偷加个logfile,
colect些statistics自己用,嘿嘿
【在 t*h 的大作中提到】 : 最简单的就是去掉那个logfile option.如果他们要save 下来,就用重定向。 : 用 > xxx.log : or | tee xxx.log : 前者没有screen output : 后者有
|
u****u 发帖数: 2308 | 17 你这个user一会儿是自己一会儿是别人,到底给谁用的啊?
【在 i*****8 的大作中提到】 : 去掉logfile option万一出了问题我就无据可查了。。。我还想着偷偷加个logfile, : colect些statistics自己用,嘿嘿
|
i*****8 发帖数: 6735 | 18 user说的是别人啊,所以要把最坏的可能性都想到。我收集的statistics无非是什么人
什么时间用了这个script之类的
【在 u****u 的大作中提到】 : 你这个user一会儿是自己一会儿是别人,到底给谁用的啊?
|
u****u 发帖数: 2308 | 19 你是想要纪录谁在什么时间运行了某个程序?
【在 i*****8 的大作中提到】 : user说的是别人啊,所以要把最坏的可能性都想到。我收集的statistics无非是什么人 : 什么时间用了这个script之类的
|
i*****8 发帖数: 6735 | 20 我是这个程序的owner。我就想知道有多少user在什么时间用了我这个程序,方便以后
show给LD看
【在 u****u 的大作中提到】 : 你是想要纪录谁在什么时间运行了某个程序?
|