FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 11-23-2010, 01:30 PM
 
Default redirecting time output

Rainer Traut wrote:
> Hi,
>
> am trying to pipe output from time command and output from a shell
> script to the mail program.
> So far it's not working as expected...
>
> # time echo "test" 2>&1 | mail -s "timetest" my@mail.com
>
> real 0m0.126s
> user 0m0.000s
> sys 0m0.000s
>
> The time command writes to stderror, but here the redirection seems to
> apply to the echo command?

Try `time echo "test"` etc. That way, it executes in a subshell, and has
one STDOUT and STDERR.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-23-2010, 03:04 PM
Rainer Traut
 
Default redirecting time output

Am 23.11.2010 15:30, schrieb m.roth@5-cent.us:
> Rainer Traut wrote:
>> Hi,
>>
>> am trying to pipe output from time command and output from a shell
>> script to the mail program.
>> So far it's not working as expected...
>>
>> # time echo "test" 2>&1 | mail -s "timetest" my@mail.com
>>
>> real 0m0.126s
>> user 0m0.000s
>> sys 0m0.000s
>>
>> The time command writes to stderror, but here the redirection seems to
>> apply to the echo command?
>
> Try `time echo "test"` etc. That way, it executes in a subshell, and has
> one STDOUT and STDERR.

Ok, yes this works.

Thx
Rainer

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-23-2010, 03:27 PM
Stephen Harris
 
Default redirecting time output

On Tue, Nov 23, 2010 at 05:04:09PM +0100, Rainer Traut wrote:
> Am 23.11.2010 15:30, schrieb m.roth@5-cent.us:
> > Rainer Traut wrote:
> >> am trying to pipe output from time command and output from a shell
> >> script to the mail program.
> >> So far it's not working as expected...
> >>
> >> # time echo "test" 2>&1 | mail -s "timetest" my@mail.com

> >> The time command writes to stderror, but here the redirection seems to
> >> apply to the echo command?

> > Try `time echo "test"` etc. That way, it executes in a subshell, and has
> > one STDOUT and STDERR.

> Ok, yes this works.

The problem you're coming across is that "time" is a shell built-in and
not an external, so the shell is parsing "time foo 2>&1" as if it was
something similar to "time (foo 2>&1)".

The two common solutions are:
1) explicitly use /usr/bin/time - eg
/usr/bin/time -p foo 2>&1

2) force a subshell - eg
(time foo) 2>&1

--

rgds
Stephen
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 05:15 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org