title: How to make stderr of OS commands ran with "!" go to Sql*plus spool?
body: <h2>Background</h2>
  
  <p>I have a long <strong>Sql*plus</strong> script that for some reason needs to run some unix commands using the exclamation mark syntax.</p>
  
  <p>I write to a spool in order to have a log file at the end of the process.</p>
  
  <p>The problem is that if an OS command fails, the <strong>stderr</strong> is lost and doesn't go to the spooled file.</p>
  
  <p><strong>Example code</strong></p>
  
  <pre><code>spool mylog.txt
  !echo alter user xxx identified by yyyy;
  alter user xxx identified by yyyy;
  !echo cp file1 folder1/
  !cp file1 folder1/
  !echo alter user yyy identified by xxx;
  alter user yyy identified by xxx;
  !echo cp file2 folder2/
  !cp file2 folder2/
  spool off
  </code></pre>
  
  <p>If one <code>cp</code> fails, I wouldn't know just by looking at mylog.txt</p>
  
  <p>Obviously doing <code>!cp file1 folder1/ &amp;&gt; mylog.txt</code> would only mess up the log beeing spooled to in unpredictable ways.</p>
  
  <h2>Question</h2>
  
  <p>What can be done in order for the the stderr of the unix commands be writen to the file beeing spooled to ?</p>
  
  <h2>Update</h2>
  
  <p>I tried <a href="https://stackoverflow.com/users/44853/lc">lc.'s</a> suggestion, appending  <code>2&gt;&amp;1</code>  at the end of every cp command in order to redirect stderr to stdout but I get this:</p>
  
  <pre><code>Enter value for 1:
  </code></pre>
  
  <h2>Update 2</h2>
  
  <p><code>SET DEFINE OFF</code> made it to not prompt for a value. It allowed me to discover that it's not only stderr that doesn't get spooled: stdout doesn't either. It seems that <strong>everything executed with "!" is un-spool-able</strong>. </p>