<?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: pipes and return codes in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001075#M914432</link>
    <description>The problem is the pipe...</description>
    <pubDate>Wed, 18 Jun 2003 15:03:15 GMT</pubDate>
    <dc:creator>Jdamian</dc:creator>
    <dc:date>2003-06-18T15:03:15Z</dc:date>
    <item>
      <title>pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001062#M914419</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;A script contains the following:&lt;BR /&gt;&lt;BR /&gt;function X&lt;BR /&gt;{&lt;BR /&gt; sed 's/^/### /p'&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;commandB | X&lt;BR /&gt;&lt;BR /&gt;My problem is to catch the code ($?) returned by commandB without using a intermediate file. I need that value to be returned to the parent process (the process that calls my script)&lt;BR /&gt;&lt;BR /&gt;any ideas ?</description>
      <pubDate>Wed, 18 Jun 2003 14:24:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001062#M914419</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2003-06-18T14:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001063#M914420</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Easiest way is to use a file:-&lt;BR /&gt;&lt;BR /&gt;commandB | &amp;gt;&amp;gt;/tmp/X&lt;BR /&gt;&lt;BR /&gt;Paula</description>
      <pubDate>Wed, 18 Jun 2003 14:27:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001063#M914420</guid>
      <dc:creator>Paula J Frazer-Campbell</dc:creator>
      <dc:date>2003-06-18T14:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001064#M914421</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Easiest way is to use a file:-&lt;BR /&gt;&lt;BR /&gt;commandB &amp;gt;&amp;gt;/tmp/X&lt;BR /&gt;&lt;BR /&gt;Paula</description>
      <pubDate>Wed, 18 Jun 2003 14:28:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001064#M914421</guid>
      <dc:creator>Paula J Frazer-Campbell</dc:creator>
      <dc:date>2003-06-18T14:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001065#M914422</link>
      <description>Hi, try&lt;BR /&gt;&lt;BR /&gt;commandB| echo $? | X&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;X will get in input the RETCOD.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;  Massimo&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Wed, 18 Jun 2003 14:28:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001065#M914422</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-18T14:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001066#M914423</link>
      <description>Hi,&lt;BR /&gt;sorry for a mispelling:&lt;BR /&gt;&lt;BR /&gt;(commandB ); echo $? | X&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt; Massimo&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Jun 2003 14:31:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001066#M914423</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-18T14:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001067#M914424</link>
      <description>Massimo, your proposal won't work, because it is equivalent to&lt;BR /&gt;&lt;BR /&gt;commandB &amp;gt; /dev/null&lt;BR /&gt;echo $? | X&lt;BR /&gt;&lt;BR /&gt;I need the output from commandB BE the input to X.</description>
      <pubDate>Wed, 18 Jun 2003 14:32:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001067#M914424</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2003-06-18T14:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001068#M914425</link>
      <description>Hi,&lt;BR /&gt;so you need both the output of the command and the retcode, is this correct ?&lt;BR /&gt;&lt;BR /&gt;  Massimo&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Jun 2003 14:34:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001068#M914425</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-18T14:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001069#M914426</link>
      <description>Yes, I need both</description>
      <pubDate>Wed, 18 Jun 2003 14:35:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001069#M914426</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2003-06-18T14:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001070#M914427</link>
      <description>Try this:&lt;BR /&gt;&lt;BR /&gt;# (commandB; echo $? &amp;gt; /tmp/rc.txt) | X&lt;BR /&gt;&lt;BR /&gt;commandB's output is passed thru the pipe while its return code is saved in /tmp/rc.txt&lt;BR /&gt;&lt;BR /&gt;Hai</description>
      <pubDate>Wed, 18 Jun 2003 14:37:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001070#M914427</guid>
      <dc:creator>Hai Nguyen_1</dc:creator>
      <dc:date>2003-06-18T14:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001071#M914428</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;How about putting commandB into a function too, ie:&lt;BR /&gt;&lt;BR /&gt;function commandBfunction&lt;BR /&gt;{&lt;BR /&gt;commandB&lt;BR /&gt;retcodeB=$?&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;You can then use retcodeB elsewhere in the script.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;&lt;BR /&gt;Darren.</description>
      <pubDate>Wed, 18 Jun 2003 14:41:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001071#M914428</guid>
      <dc:creator>Darren Prior</dc:creator>
      <dc:date>2003-06-18T14:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001072#M914429</link>
      <description>function Z&lt;BR /&gt;{&lt;BR /&gt; commandB&lt;BR /&gt; RVAL=$?&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Z | X&lt;BR /&gt;&lt;BR /&gt;return $RVAL&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Darren, it's a good idea but it still doesn't work because Z and X are run in two subshells. See the manual pages of sh-posix(1):&lt;BR /&gt;&lt;BR /&gt;A pipeline is a sequence of one or more commands separated by a bar&lt;BR /&gt;      (|) and optionally preceded by an exclamation mark (!).  The standard&lt;BR /&gt;      output of each command but the last is connected by a pipe (see&lt;BR /&gt;      pipe(2)) to the standard input of the next command.  Each command is&lt;BR /&gt;      run as a separate process; the shell waits for the last command to&lt;BR /&gt;      terminate.</description>
      <pubDate>Wed, 18 Jun 2003 14:51:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001072#M914429</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2003-06-18T14:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001073#M914430</link>
      <description>Actually this code should be what you expect.&lt;BR /&gt;&lt;BR /&gt;Rewritten function X:&lt;BR /&gt;function X&lt;BR /&gt;{&lt;BR /&gt;RC=`echo $?`&lt;BR /&gt;sed 's/^/###/p'&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Rewrite "commandD | X" to:&lt;BR /&gt;&lt;BR /&gt;export RC&lt;BR /&gt;commandB | X&lt;BR /&gt;echo $RC # this is the return code of commandB&lt;BR /&gt;&lt;BR /&gt;Hai</description>
      <pubDate>Wed, 18 Jun 2003 14:55:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001073#M914430</guid>
      <dc:creator>Hai Nguyen_1</dc:creator>
      <dc:date>2003-06-18T14:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001074#M914431</link>
      <description>Hi,&lt;BR /&gt;use&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;export RETVALB=$?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;should to the final trick.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;  Massimo&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Jun 2003 14:55:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001074#M914431</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-18T14:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001075#M914432</link>
      <description>The problem is the pipe...</description>
      <pubDate>Wed, 18 Jun 2003 15:03:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001075#M914432</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2003-06-18T15:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001076#M914433</link>
      <description>OK. How about this:&lt;BR /&gt;&lt;BR /&gt;function Z &lt;BR /&gt;{ &lt;BR /&gt;commandB &lt;BR /&gt;RVAL=$? &lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;export RVAL&lt;BR /&gt;Z | X &lt;BR /&gt;echo $RVAL &lt;BR /&gt;&lt;BR /&gt;This should be independent of the pipe and should always work since RVAL is a global variable.&lt;BR /&gt;&lt;BR /&gt;Hai</description>
      <pubDate>Wed, 18 Jun 2003 15:08:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001076#M914433</guid>
      <dc:creator>Hai Nguyen_1</dc:creator>
      <dc:date>2003-06-18T15:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001077#M914434</link>
      <description>No, Hi... it doesn't work...&lt;BR /&gt;&lt;BR /&gt;For executing Z, the shell runs a subshell. RVAL value is changed in this subshell. Thus, when subshell dies, its RVAL variable is destroyed.&lt;BR /&gt;&lt;BR /&gt;I think the only solution is using an intermediate file.</description>
      <pubDate>Wed, 18 Jun 2003 15:18:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001077#M914434</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2003-06-18T15:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001078#M914435</link>
      <description>I see the point - it doesn't work for the same reason that my idea didn't work! ;-(&lt;BR /&gt;&lt;BR /&gt;Although it's more messy, I think that dumping the return code into a file is your best option, though it's been fun trying to find ways round it!&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;&lt;BR /&gt;Darren.</description>
      <pubDate>Wed, 18 Jun 2003 15:23:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001078#M914435</guid>
      <dc:creator>Darren Prior</dc:creator>
      <dc:date>2003-06-18T15:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001079#M914436</link>
      <description>function Z &lt;BR /&gt;{ &lt;BR /&gt;commandB &lt;BR /&gt;RVAL=`echo $?` &lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;export RVAL &lt;BR /&gt;Z | X &lt;BR /&gt;echo $RVAL&lt;BR /&gt;&lt;BR /&gt;I caught the error in function Z.  RVAL=$? is corrected to RVAL=`echo $?`&lt;BR /&gt;&lt;BR /&gt;Hai</description>
      <pubDate>Wed, 18 Jun 2003 15:27:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001079#M914436</guid>
      <dc:creator>Hai Nguyen_1</dc:creator>
      <dc:date>2003-06-18T15:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001080#M914437</link>
      <description>It works:&lt;BR /&gt;&lt;BR /&gt;The trick is the subshell, you put both output to the suvsequent command. When you want to test the RETCOD, you seach with awk for it.&lt;BR /&gt;&lt;BR /&gt;[massimo@localhost massimo]$ (ls infos.txt; echo RETCODE=$?) | grep -v ciccio&lt;BR /&gt;infos.txt&lt;BR /&gt;RETCODE=0&lt;BR /&gt;[massimo@localhost massimo]$ (ls infos1.txt; echo RETCODE=$?) | grep -v ciccio&lt;BR /&gt;ls: infos1.txt: No such file or directory&lt;BR /&gt;RETCODE=1&lt;BR /&gt;[massimo@localhost massimo]$&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;As you can see:&lt;BR /&gt;&lt;BR /&gt;- no file&lt;BR /&gt;- both output of the command, standard error, and return code are echoed to the command after the pipe.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;  Massimo</description>
      <pubDate>Thu, 19 Jun 2003 04:52:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001080#M914437</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-06-19T04:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: pipes and return codes</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001081#M914438</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;I've tried ... like others :-), but with no success, and I can't see any 'generic' way of doing it without a temp file. Some solutions will work depending of the command on the right side of the pipe, but it's always easy to find a pipe command which wouldn't work ... For example, if I need to grep ALL output from the left side, no solution using echo $? can work.&lt;BR /&gt;&lt;BR /&gt;Sorry for you ...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jun 2003 06:06:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipes-and-return-codes/m-p/3001081#M914438</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-06-19T06:06:14Z</dc:date>
    </item>
  </channel>
</rss>

