<?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: Too late to redirect stdout/stderr after script is running?? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651070#M240488</link>
    <description>As Greg suggested, exec is the way to do this. From the man pages for sh-posix and ksh:&lt;BR /&gt; &lt;BR /&gt;"If no arguments are given, the effect of this command is to modify file descriptors as prescribed by the input/output redirection list."&lt;BR /&gt; &lt;BR /&gt;So, you can redirect stdin, stdout and stderr. So for your example:&lt;BR /&gt; &lt;BR /&gt;exec 1&amp;gt;$STDOUT 2&amp;gt;$STDERR&lt;BR /&gt; &lt;BR /&gt;You can also redirect stderr into stdout:&lt;BR /&gt; &lt;BR /&gt;exec 2&amp;gt;&amp;amp;1&lt;BR /&gt; &lt;BR /&gt;Or any of the redirection features of the shell. There is no limit on using exec multiple times with different redirection options.</description>
    <pubDate>Mon, 17 Oct 2005 19:47:41 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2005-10-17T19:47:41Z</dc:date>
    <item>
      <title>Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651063#M240481</link>
      <description>I would like to redirect stdout and stderr from within a shell script.  I've done this before when "calling" another script:&lt;BR /&gt;&lt;BR /&gt;myscript 1&amp;gt;/tmp/junk 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;But what I'm trying to do in this case is capture the output from the actual running script itself after it has started.  Is this possible?  For example:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;# Sample script&lt;BR /&gt;&lt;BR /&gt;export STDOUT=/tmp/junk&lt;BR /&gt;export STDERR=/tmp/junkerror&lt;BR /&gt;&lt;BR /&gt;echo Hello World&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;I'm just not sure of the syntax or whether it's even possible.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;Tim</description>
      <pubDate>Mon, 17 Oct 2005 12:15:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651063#M240481</guid>
      <dc:creator>Tim Medford</dc:creator>
      <dc:date>2005-10-17T12:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651064#M240482</link>
      <description>I'm not exactly clear on what you mean by after the script has started! How ever a if your script was:&lt;BR /&gt;echo "Hello World" 1&amp;gt;/tmp/junk 2&amp;gt;/tmp/junkerror&lt;BR /&gt;I believe you would get what your example was trying for.&lt;BR /&gt;&lt;BR /&gt;The tee command may also give you some more options.</description>
      <pubDate>Mon, 17 Oct 2005 12:33:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651064#M240482</guid>
      <dc:creator>Ken Grabowski</dc:creator>
      <dc:date>2005-10-17T12:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651065#M240483</link>
      <description>Thanks Ken.&lt;BR /&gt;&lt;BR /&gt;I guess I didn't give a very good example.  I knew I could redirect the output for that single echo command as you suggested.&lt;BR /&gt;&lt;BR /&gt;Instead of just a single echo command the script actually contains dozens of commands doing a variety of things.  &lt;BR /&gt;&lt;BR /&gt;I'm trying to capture all the output from all the commands without individually redirecting all of them.</description>
      <pubDate>Mon, 17 Oct 2005 12:36:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651065#M240483</guid>
      <dc:creator>Tim Medford</dc:creator>
      <dc:date>2005-10-17T12:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651066#M240484</link>
      <description>You can use "exec 2&amp;gt;&amp;amp;1" to redirect stderr to&lt;BR /&gt;stdout at the desired point in your script.&lt;BR /&gt;Is that what you want?&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Oct 2005 12:46:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651066#M240484</guid>
      <dc:creator>Gregory Fruth</dc:creator>
      <dc:date>2005-10-17T12:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651067#M240485</link>
      <description>I can think of an ugly way...&lt;BR /&gt;for it in a for loop (with one pass).&lt;BR /&gt;&lt;BR /&gt;for i in 1&lt;BR /&gt;do&lt;BR /&gt;  mycommand&lt;BR /&gt;  nextcommand&lt;BR /&gt;  another command&lt;BR /&gt;  yet another command&lt;BR /&gt;done &amp;gt; myoutputfile 2&amp;gt;&amp;amp;1 &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Oct 2005 12:50:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651067#M240485</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2005-10-17T12:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651068#M240486</link>
      <description>Gregory - Thanks, that's exactly what I needed, I just couldn't figure out the syntax.&lt;BR /&gt;&lt;BR /&gt;exec 1&amp;gt;/tmp/junk.out&lt;BR /&gt;exec 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;do other stuff...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Oct 2005 12:51:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651068#M240486</guid>
      <dc:creator>Tim Medford</dc:creator>
      <dc:date>2005-10-17T12:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651069#M240487</link>
      <description>Thats a little different than what I was getting from your submission. There is no way to globally change where stdout and stderr are pointing.&lt;BR /&gt;&lt;BR /&gt;You can of course use other programming techniques to simplify the task. If all the scripts that you are calling use the same redirection, try creating a function that takes the scripts as a parameter to the function. Then run that script from the function and apply the redirection there. That way you program it once and use it many times.&lt;BR /&gt;&lt;BR /&gt;Best of luck!</description>
      <pubDate>Mon, 17 Oct 2005 13:13:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651069#M240487</guid>
      <dc:creator>Ken Grabowski</dc:creator>
      <dc:date>2005-10-17T13:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651070#M240488</link>
      <description>As Greg suggested, exec is the way to do this. From the man pages for sh-posix and ksh:&lt;BR /&gt; &lt;BR /&gt;"If no arguments are given, the effect of this command is to modify file descriptors as prescribed by the input/output redirection list."&lt;BR /&gt; &lt;BR /&gt;So, you can redirect stdin, stdout and stderr. So for your example:&lt;BR /&gt; &lt;BR /&gt;exec 1&amp;gt;$STDOUT 2&amp;gt;$STDERR&lt;BR /&gt; &lt;BR /&gt;You can also redirect stderr into stdout:&lt;BR /&gt; &lt;BR /&gt;exec 2&amp;gt;&amp;amp;1&lt;BR /&gt; &lt;BR /&gt;Or any of the redirection features of the shell. There is no limit on using exec multiple times with different redirection options.</description>
      <pubDate>Mon, 17 Oct 2005 19:47:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651070#M240488</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-10-17T19:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Too late to redirect stdout/stderr after script is running??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651071#M240489</link>
      <description>You can start log files in different mode using exec command. &lt;BR /&gt;&lt;BR /&gt;exec 2&amp;gt;/tmp/err.log 1&amp;gt;/tmp/output.log&lt;BR /&gt;&lt;BR /&gt;Ways more:&lt;BR /&gt;&lt;BR /&gt;a)&lt;BR /&gt;&lt;BR /&gt;(&lt;BR /&gt;echo "ok"; # std output command&lt;BR /&gt;ls /stand/muthu; # std error command ;)&lt;BR /&gt;) 1&amp;gt; /tmp/out.log 2&amp;gt;/tmp/err.log&lt;BR /&gt;&lt;BR /&gt;b)&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;echo "ok"; # std output command&lt;BR /&gt;ls /stand/muthu; # std error command ;)&lt;BR /&gt;} 1&amp;gt; /tmp/out.log 2&amp;gt;/tmp/err.log&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Tue, 18 Oct 2005 01:55:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/too-late-to-redirect-stdout-stderr-after-script-is-running/m-p/3651071#M240489</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-10-18T01:55:38Z</dc:date>
    </item>
  </channel>
</rss>

