Capture shell output

Ricardo Hallak hallak at MODEL.IAG.USP.BR
Sat Jun 13 16:25:05 EDT 2009


Hi,

you can redirect your date command to an external file:
'q time'
tc=subwrd(result,3)
'! date -u -d 'tc' +"%Y%m%d %H%M%S" > date.txt'

In the sequence, you could read date.txt using the "read" grads command.

dateread=read('date.txt')
vardate=sublin(dateread,2)
say vardate
...
etc

I hope this help,
Ricardo

On Sat, 13 Jun 2009 13:56:08 -0500, P.R. wrote
> Is it possible to capture stdout from a shell command?
> Im trying to do the following within a grads script (in a linux shell
> environment)?
>
> * use linux shell's 'date' function to process time...
> 'q time'
> tc=subwrd(result,3)
> '!date -u -d 'tc' +"%Y%m%d %H%M%S"'
>
> * this doesn't work; result is empty
>
> say 'res: 'result
>
> ymd=subwrd(result,1)
> hms=subwrd(result,2)
> say 'ymd: 'ymd
> say 'hms: 'hms
>
> Can anyone please confirm this, or provide a work-around to be able
> to retrieve&save stdout from a shell command?
>
> Thanks,
> P.Romero


Ricardo Hallak

Department of Atmospheric Sciences (DCA)
Institute of Astronomy, Geophysics and Atmospheric Sciences (IAG)
University of São Paulo (USP)
Rua do Matão, 1226 - Cidade Universitária - São Paulo SP 05508-900
Phone.: +55 (11) 3091-2834
Fax: +55 (11) 3091-4714



More information about the gradsusr mailing list