Redian新闻
>
为什么time命令无法重定向?
avatar
为什么time命令无法重定向?# Unix - 噫吁兮,危乎高哉
v*t
1
我用$>time cat filename > test.dat时
test.dat的内容是 cat filename 的结果。
但time的结果还是显示在终端上,而没有输入到filename中。
另外我用$>time command 〉tmp 时,tmp内容为空,time
的结果显示在终端上
avatar
o*z
2
/usr/bin/time

【在 v**t 的大作中提到】
: 我用$>time cat filename > test.dat时
: test.dat的内容是 cat filename 的结果。
: 但time的结果还是显示在终端上,而没有输入到filename中。
: 另外我用$>time command 〉tmp 时,tmp内容为空,time
: 的结果显示在终端上

avatar
t*n
3
(time cat filename) > test.dat

【在 v**t 的大作中提到】
: 我用$>time cat filename > test.dat时
: test.dat的内容是 cat filename 的结果。
: 但time的结果还是显示在终端上,而没有输入到filename中。
: 另外我用$>time command 〉tmp 时,tmp内容为空,time
: 的结果显示在终端上

avatar
r*a
4

It does NOT work.
两年前俺就发现time的输出不能重定向,即使俺把stderr重定向到stdout后再重定向到文件
都不行,当时只好用script这个命令解决了。

【在 t****n 的大作中提到】
: (time cat filename) > test.dat
avatar
q*m
5

I posted this on Linux board:
for sh/bash,
%time cat filename 2> time.out
for csh/tcsh/bash
%(time cat finename) >& time.out
Does this work for you?

【在 r**a 的大作中提到】
:
: It does NOT work.
: 两年前俺就发现time的输出不能重定向,即使俺把stderr重定向到stdout后再重定向到文件
: 都不行,当时只好用script这个命令解决了。

avatar
v*t
6
The sencond one can use. Thank you very much.

【在 q*****m 的大作中提到】
:
: I posted this on Linux board:
: for sh/bash,
: %time cat filename 2> time.out
: for csh/tcsh/bash
: %(time cat finename) >& time.out
: Does this work for you?

avatar
r*a
7
在sh/bash中可以用:
(time cat filename) > time.out 2>&1
刚才俺才意识到问什么我以前在bash中用time cat filename > time.out 2>&1 (就是俺说
的把stderr重定向到stdout后再重定向到文件)行不通,原来是time认为它的参数是
cat filename > time.out 2&1,故而其输出根本就没有被重定向,而是cat的输出被重定
向了,FT!!!!! 现在强行规定了命令执行顺序就好了。
BTW I/O redirection in csh is not consistent with other shells, and csh itself
is not suitable to be used to write scripts, so I almost never use it.

【在 q*****m 的大作中提到】
:
: I posted this on Linux board:
: for sh/bash,
: %time cat filename 2> time.out
: for csh/tcsh/bash
: %(time cat finename) >& time.out
: Does this work for you?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。