如何捕获unix time命令的输出? [英] How to capture output of unix time command?

查看:53
本文介绍了如何捕获unix time命令的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用perl执行unix time命令,并捕获输出(具体来说,执行命令所需的时间)。


i尝试使用系统命令:

system(" time command ");

但是,当我尝试捕获输出时,捕获输出不包含金额我尝试做的时候执行


的时间:

$ var =`time command `;

存在同样的问题(命令的输出保存在变量中;但是,时间不是)


那么,我该如何捕获时间呢采用unix命令执行?

I want to execute a unix time command using perl, and capture the output (specifically, the time it takes the command to execute).

i tried using the system command:
system("time command ");
however, when i try to capture the output, the capture output does not contain the amount of time it took to execute

when i try to do:
$var = `time command `;
there is the same problem (the ouput from the command is saved in the variable; however, the time is not)

So, how do i capture the time it takes a unix command to execute?

推荐答案

var =`time 命令`;

有相同的问题(来自命令的输出保存在变量中;但是,时间不是)


那么,我如何捕获执行unix命令所需的时间?
var = `time command `;
there is the same problem (the ouput from the command is saved in the variable; however, the time is not)

So, how do i capture the time it takes a unix command to execute?


你的脚本正是你所设计的要做到这一点。它将您发出的命令的输出存储在您指定的变量中。即使在命令行上,命令也不会告诉你执行需要多长时间。听起来你想在执行系统命令时对Perl进行某种基准测试。不幸的是,我没有任何基准测试经验,也没有多大帮助。


问候,


Jeff
Your script is doing exactly what you designed it to do. It is storing the output of the command you issued in the variable you specified. Even on the command line the command won''t tell you how long it took to execute. It sounds like you want to do some sort of benchmarking of Perl while executing system commands. Unfortunately, I don''t have any experience with benchmarking and couldn''t be much help.

Regards,

Jeff


当我输入time 命令在命令行我得到以下内容:


...

输出线

....

真实0.5

用户0.4

sys 0.0

when i type in "time command " at the command line i get the following:

...
lines of output
....
real 0.5
user 0.4
sys 0.0

I want to store ALL the above output in a file (using a perl script). When i try to do this, i am only able to store the "lines of ouput" part. I am unable to store those last three lines, and i cant figure out why I am unable to.


这篇关于如何捕获unix time命令的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆