<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823176#M720922</link>
    <description>&lt;BR /&gt;Do you mean that you want to capture stderr to a variable? Yes.&lt;BR /&gt;&lt;BR /&gt;Using command substitution:&lt;BR /&gt;&lt;BR /&gt;errormsg=$(command 2&amp;gt;&amp;amp;1 &amp;gt;/dev/ull)&lt;BR /&gt;&lt;BR /&gt;The order of redirection is important! You first want to reassign stderr to what stdout is using, then redirect stdout to null if you don't it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Using pipes and the shell's read command:&lt;BR /&gt;&lt;BR /&gt;( command | read ouput ) 2&amp;gt;&amp;amp;1 | read error&lt;BR /&gt;&lt;BR /&gt;This pipeline often confuses people. The grouping with parans is important because you want the stderr of the command to pass to the second read, not through first.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 10 Oct 2002 18:09:44 GMT</pubDate>
    <dc:creator>Jordan Bean</dc:creator>
    <dc:date>2002-10-10T18:09:44Z</dc:date>
    <item>
      <title>Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823172#M720918</link>
      <description>Can you assign stderr to a variable?&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Oct 2002 17:54:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823172#M720918</guid>
      <dc:creator>Andrew Porter_1</dc:creator>
      <dc:date>2002-10-10T17:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823173#M720919</link>
      <description>Hi Andrew:&lt;BR /&gt;&lt;BR /&gt;This works:&lt;BR /&gt;&lt;BR /&gt;# X=`print -u2 "hello andrew" 2&amp;gt;&amp;amp;1`&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 10 Oct 2002 18:03:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823173#M720919</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-10-10T18:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823174#M720920</link>
      <description>You can do something like this:&lt;BR /&gt;&lt;BR /&gt;XX=$(my_command 2&amp;gt;&amp;amp;1)&lt;BR /&gt;&lt;BR /&gt;${XX} will then contain both stdout's and stderr's output but to get them separately is a bit more difficult.&lt;BR /&gt;&lt;BR /&gt;ERRS=""&lt;BR /&gt;TFILE=/var/tmp/XX${$}.err &lt;BR /&gt;&lt;BR /&gt;XX=$(my_command 2&amp;gt;${TFILE})&lt;BR /&gt;if [[ -s ${TFILE} ]]&lt;BR /&gt;  then&lt;BR /&gt;    ERRS=$(cat ${TFILE})&lt;BR /&gt;  fi&lt;BR /&gt;rm -f ${TFILE}&lt;BR /&gt;&lt;BR /&gt;Now ${XX} contains the output of stdout and ${ERRS} contains that of stderr&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Oct 2002 18:05:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823174#M720920</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-10-10T18:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823175#M720921</link>
      <description>Didn't work&lt;BR /&gt;&lt;BR /&gt;Here what I am tring to do...&lt;BR /&gt;&lt;BR /&gt;I am trying to put the elaspe time of a command into a variable&lt;BR /&gt;&lt;BR /&gt;I was using &lt;BR /&gt;&lt;BR /&gt;time {command}&lt;BR /&gt;&lt;BR /&gt;to get the elaspe time</description>
      <pubDate>Thu, 10 Oct 2002 18:08:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823175#M720921</guid>
      <dc:creator>Andrew Porter_1</dc:creator>
      <dc:date>2002-10-10T18:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823176#M720922</link>
      <description>&lt;BR /&gt;Do you mean that you want to capture stderr to a variable? Yes.&lt;BR /&gt;&lt;BR /&gt;Using command substitution:&lt;BR /&gt;&lt;BR /&gt;errormsg=$(command 2&amp;gt;&amp;amp;1 &amp;gt;/dev/ull)&lt;BR /&gt;&lt;BR /&gt;The order of redirection is important! You first want to reassign stderr to what stdout is using, then redirect stdout to null if you don't it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Using pipes and the shell's read command:&lt;BR /&gt;&lt;BR /&gt;( command | read ouput ) 2&amp;gt;&amp;amp;1 | read error&lt;BR /&gt;&lt;BR /&gt;This pipeline often confuses people. The grouping with parans is important because you want the stderr of the command to pass to the second read, not through first.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Oct 2002 18:09:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823176#M720922</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2002-10-10T18:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823177#M720923</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;OK, thy this:&lt;BR /&gt;&lt;BR /&gt;# time date 2&amp;gt; /tmp/mytime &lt;BR /&gt;# X=`# echo $X&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 10 Oct 2002 18:13:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823177#M720923</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-10-10T18:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823178#M720924</link>
      <description>Yes you can.&lt;BR /&gt;&lt;BR /&gt;V=$(ls junk 2&amp;gt;&amp;amp;1 &amp;gt;V.out)&lt;BR /&gt;In this case, $V contains stderr from "ls junk" and V.out contains stdout.&lt;BR /&gt;&lt;BR /&gt;You could capture stderr and stdout both to the variable:&lt;BR /&gt;V=$(ls junk 2&amp;gt;&amp;amp;1)&lt;BR /&gt;&lt;BR /&gt;Lastly, to capture stderr in a variable and send stdout to the screen:&lt;BR /&gt;V=$(ls junk 2&amp;gt;&amp;amp;1 &amp;gt;$(tty))&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 10 Oct 2002 18:13:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823178#M720924</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2002-10-10T18:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823179#M720925</link>
      <description>Oops!  I meant to say "If you want to send STDOUT to the bit bucket".&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 10 Oct 2002 18:25:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823179#M720925</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2002-10-10T18:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823180#M720926</link>
      <description>For your example:&lt;BR /&gt;&lt;BR /&gt;etime=(time {command} 2&amp;gt;&amp;amp;1 &amp;gt;$(tty))&lt;BR /&gt;echo $etime&lt;BR /&gt;&lt;BR /&gt;If you want to send stderr to the bit bucket:&lt;BR /&gt;etime=(time {command} 2&amp;gt;&amp;amp;1 &amp;gt;/dev/null)&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 10 Oct 2002 18:25:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823180#M720926</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2002-10-10T18:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823181#M720927</link>
      <description>That's weird!  My "Oops" reply is posted before my "For your example" reply.&lt;BR /&gt;&lt;BR /&gt;I'll have to point this out to Dan (the forums admin).&lt;BR /&gt;&lt;BR /&gt;By the way, welcome to the forums Andrew.  It's the best (even if there's been a few problems today with the site upgrade).&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 10 Oct 2002 18:29:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823181#M720927</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2002-10-10T18:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823182#M720928</link>
      <description>Thanks for all your help guys heres what I've come up with...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;t=$(time {Command} 2&amp;gt;&amp;amp;1  &amp;gt;/dev/null|grep real|awk '{print $2}')&lt;BR /&gt;&lt;BR /&gt;Thanks again</description>
      <pubDate>Thu, 10 Oct 2002 18:36:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823182#M720928</guid>
      <dc:creator>Andrew Porter_1</dc:creator>
      <dc:date>2002-10-10T18:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823183#M720929</link>
      <description>&lt;BR /&gt;You can drop this grep this way:&lt;BR /&gt;&lt;BR /&gt;t=$(time command 2&amp;gt;&amp;amp;1 &amp;gt;/dev/null | awk '$1~/^real$/{print $2}')&lt;BR /&gt;&lt;BR /&gt;Or you can capture all times this to any array:&lt;BR /&gt;&lt;BR /&gt;set -A t $(time command 2&amp;gt;&amp;amp;1 &amp;gt;/dev/null | awk '{print $2 $4 $6}')&lt;BR /&gt;echo real $t&lt;BR /&gt;echo all ${t[@]}&lt;BR /&gt;echo real ${t[0]} user ${t[1]} sys ${t[2]}&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Oct 2002 18:51:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823183#M720929</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2002-10-10T18:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823184#M720930</link>
      <description>Hi (again) Andrew:&lt;BR /&gt;&lt;BR /&gt;Another way of capturing just the timing statistics was shown in my second post.  All three metrics are assigned to the variable as a simple string.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 10 Oct 2002 18:56:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting/m-p/2823184#M720930</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-10-10T18:56:52Z</dc:date>
    </item>
  </channel>
</rss>

