<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Newer builds of GrADS also have an intrinsic function in the scripting language that will issue a shell command and capture the output.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>sys (<i>command</i>)</b><br>
This function was added in version 2.1.1.b0. It submits the specified command to the shell and returns the resulting text stream that gets sent to standard output (stdout). The command is passed to /bin/sh. There is no way to check if the command succeeded;
 the return code is not captured, and an empty result could mean that the command has no output or that the command failed. Any error notifications or text streams sent to standard error (stderr) will appear in the console window and not the returned text unless
 you explicitly include a capture of stderr in your command string.<o:p></o:p></p>
<p class="MsoNormal">Consider the following script test_sys.gs:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">cmd1="ls ./foo"<br>
cmd2="ls ./foo 2>&1"<br>
cmd3='echo Hello, world!'<br>
res1=sys(cmd1); say 'cmd1 returned ->'res1'<-'<br>
res2=sys(cmd2); say 'cmd2 returned ->'res2'<-'<br>
res3=sys(cmd3); say 'cmd3 returned ->'res3'<-'<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The session in the GrADS command window when running test_sys.gs looks like this:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in">ga-> test_sys<br>
ls: ./foo: No such file or directory<br>
cmd1 returned -><-<br>
cmd2 returned ->ls: ./foo: No such file or directory<br>
<-<br>
cmd3 returned ->Hello, world!<br>
<-<br>
ga-><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">-- <span style="color:black"><br>
Jennifer Miletta Adams<br>
ADNET Systems, Inc.<br>
NASA/GSFC, Code 610.2</span><o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;color:black">Building 32, Room S159<br>
(301) 614-6070<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">gradsusr <gradsusr-bounces@gradsusr.org> on behalf of Davide Sachetti <davide.sacchetti@arpal.liguria.it><br>
<b>Reply-To: </b>GrADS Users Forum <gradsusr@gradsusr.org><br>
<b>Date: </b>Tuesday, October 20, 2020 at 3:36 AM<br>
<b>To: </b>"gradsusr@gradsusr.org" <gradsusr@gradsusr.org><br>
<b>Subject: </b>[EXTERNAL] Re: [gradsusr] shell command within grads script<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">the simplest way is to redirect shell output to a file (!date >/tmp/x),
<br>
then read it (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__cola.gmu.edu_grads_gadoc_script.html&d=DwMFaQ&c=ApwzowJNAKKw3xye91w7BE1XMRKi2LN9kiMk5Csz9Zk&r=M2mFZsxo0ZoztoK2Lyoypu1kKkBVKyEoM9CXGWO42zk&m=YdeK14LAwOILDorq-HRrVxRz6zIYU2uymXt97Jz3S1E&s=nGpp4SbYO3yOtlYygMHXxVoR3mGl1YL6dmR89kgE8fw&e=">http://cola.gmu.edu/grads/gadoc/script.html</a>)
<br>
<br>
in opengrads there is at least one extension (I wrote one) that gets <br>
the output of external commands, but if you don't know about extensions <br>
the first solution may be faster to implement <br>
<br>
Bye bye <br>
Davide <br>
<br>
On Mon, 2020-10-19 at 17:26 -0400, Muthuvel Chelliah - NOAA Federal <br>
wrote: <br>
<span style="color:black">> Semyon, Jeff, </span><br>
<span style="color:black">> </span><br>
<span style="color:black">> Thanks for the replies. </span><br>
<span style="color:black">> </span><br>
<span style="color:black">> a) I know that the date command with the options I had asked, will
</span><br>
<span style="color:black">> give the </span><br>
<span style="color:black">> result at the grads command line with a ! before that command.
</span><br>
<span style="color:black">> </span><br>
<span style="color:black">> b) I also know the second round about way my manipulating the output
</span><br>
<span style="color:black">> from the q time output (but how to do few days ago?).
</span><br>
<span style="color:black">> </span><br>
<span style="color:black">> I was only curious if there was a way from a) above, of possibly
</span><br>
<span style="color:black">> storing </span><br>
<span style="color:black">> that output in a variable as part of a grads script variable itself.
</span><br>
<span style="color:black">> I guess, it is difficult, and not doable!! </span><br>
<span style="color:black">> </span><br>
<span style="color:black">> Thanks again </span><br>
<span style="color:black">> Muthu </span><br>
<span style="color:black">>  </span><br>
<span style="color:black">> ------------------------------------------------ </span>
<br>
<span style="color:black">> Dr. Muthuvel Chelliah, eMail: <a href="mailto:Muthuvel.Chelliah@noaa.gov">
Muthuvel.Chelliah@noaa.gov</a> </span><br>
<span style="color:black">> Rm. 3008, Climate Prediction Center, Ph: (301) 683-3393
</span><br>
<span style="color:black">> NCEP/NWS/NOAA/U.S.Dept.of Commerce, </span><br>
<span style="color:black">> 5830, University Research Court, NCWCP, </span><br>
<span style="color:black">> College Park, MD 20740 </span><br>
<span style="color:black">> </span><br>
<span style="color:black">> </span><br>
<span style="color:black">> On Mon, Oct 19, 2020 at 4:54 PM Jeff Duda <<a href="mailto:jeffduda319@gmail.com">jeffduda319@gmail.com</a>>
</span><br>
<span style="color:black">> wrote: </span><br>
<span style="color:black">> > You can try prompting the linux command with "!" and hopefully the
</span><br>
<span style="color:black">> > script recognizes the result and stores it properly.
</span><br>
<span style="color:black">> > </span><br>
<span style="color:black">> > I see that you're attempting to do something that would require
</span><br>
<span style="color:black">> > lots of code in a grads script, but hopefully you know that you can
</span><br>
<span style="color:black">> > query the valid time of data using 'q time' and parse the data
</span><br>
<span style="color:black">> > using the 'sublin()', 'subwrd()', and 'substr()' functions internal
</span><br>
<span style="color:black">> > to GrADS' scripting language. </span><br>
<span style="color:black">> > </span><br>
<span style="color:black">> > Jeff Duda </span><br>
<span style="color:black">> > </span><br>
<span style="color:black">> > On Mon, Oct 19, 2020 at 1:56 PM Muthuvel Chelliah - NOAA Federal <
</span><br>
<span style="color:black">> > <a href="mailto:muthuvel.chelliah@noaa.gov">muthuvel.chelliah@noaa.gov</a>> wrote:
</span><br>
<span style="color:black">> > > Hello folks, </span><br>
<span style="color:black">> > > </span><br>
<span style="color:black">> > > How can I set the result of the following linux shell command
</span><br>
<span style="color:black">> > > to a variable (time_var) within a Cola grads script? which can be
</span><br>
<span style="color:black">> > > assigned </span><br>
<span style="color:black">> > > to set time command, via 'set time 'time_var </span>
<br>
<span style="color:black">> > > </span><br>
<span style="color:black">> > > date -d "3 days ago" +%d%b%Y </span><br>
<span style="color:black">> > > </span><br>
<span style="color:black">> > > Thanks </span><br>
<span style="color:black">> > > Muthu </span><br>
<span style="color:black">> > > ------------------------------------------------ </span>
<br>
<span style="color:black">> > > Dr. Muthuvel Chelliah, eMail: <a href="mailto:Muthuvel.Chelliah@noaa.gov">
Muthuvel.Chelliah@noaa.gov</a> </span><br>
<span style="color:black">> > > Rm. 3008, Climate Prediction Center, Ph: (301) 683-3393
</span><br>
<span style="color:black">> > > NCEP/NWS/NOAA/U.S.Dept.of Commerce, </span><br>
<span style="color:black">> > > 5830, University Research Court, NCWCP, </span><br>
<span style="color:black">> > > College Park, MD 20740 </span><br>
<span style="color:black">> > > _______________________________________________ </span>
<br>
<span style="color:black">> > > gradsusr mailing list </span><br>
<span style="color:black">> > > <a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a>
</span><br>
<span style="color:black">> > > <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__gradsusr.org_mailman_listinfo_gradsusr&d=DwMFaQ&c=ApwzowJNAKKw3xye91w7BE1XMRKi2LN9kiMk5Csz9Zk&r=M2mFZsxo0ZoztoK2Lyoypu1kKkBVKyEoM9CXGWO42zk&m=YdeK14LAwOILDorq-HRrVxRz6zIYU2uymXt97Jz3S1E&s=nAiCz20baQhtExK-bbkfiFgLOkGnAqo2LwZQAS1Kpt8&e=">
http://gradsusr.org/mailman/listinfo/gradsusr</a> </span><br>
<span style="color:black">> > </span><br>
<span style="color:black">> > </span><br>
<span style="color:black">> > _______________________________________________ </span>
<br>
<span style="color:black">> > gradsusr mailing list </span><br>
<span style="color:black">> > <a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a>
</span><br>
<span style="color:black">> > <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__gradsusr.org_mailman_listinfo_gradsusr&d=DwMFaQ&c=ApwzowJNAKKw3xye91w7BE1XMRKi2LN9kiMk5Csz9Zk&r=M2mFZsxo0ZoztoK2Lyoypu1kKkBVKyEoM9CXGWO42zk&m=YdeK14LAwOILDorq-HRrVxRz6zIYU2uymXt97Jz3S1E&s=nAiCz20baQhtExK-bbkfiFgLOkGnAqo2LwZQAS1Kpt8&e=">
http://gradsusr.org/mailman/listinfo/gradsusr</a> </span><br>
<br>
<br>
<br>
<span style="font-size:7.5pt;font-family:"Arial",sans-serif;color:red">Attenzione ARPAL ha cambiato indirizzi digitali, i nuovi indirizzi di e-mail sono composti dall'attuale nome.cognome seguito da @arpal.liguria.it, quindi nome.cognome@arpal.liguria.it</span><br>
<br>
<o:p></o:p></p>
</div>
</body>
</html>