title: XP_CMDSHELL how to capture return value?
body: <p>I need to write an console application that returns a return code that can be captured through xp_cmdshell.</p>
  
  <p>I started with c# code as follows,</p>
  
  <pre><code>class Program
      {
          static int Main(string[] args)
          {
              //make sure the correct number of arguments are being passed.
              if (args.Length !=5)
              {
                  Console.WriteLine("not thr right number of args. \nUsage SFTPUploadFile &lt;host&gt; &lt;port&gt; &lt;username&gt; &lt;password&gt; &lt;localFilePath&gt;");
                  return 1;
              }
  
              return 0;        
          }
  
      }
  </code></pre>
  
  <p>The XP_cmdhsell I am using some code I found</p>
  
  <pre><code>declare  @rc int
  
  create table #output (id int identity(1,1), output nvarchar(255) null)
  insert #output (output) exec @rc = master..xp_cmdshell 'd:\FILENAME PARA1 PARA2 PARA3 PARA4 PARA5'
  select * from #output where output is not null order by id
  drop table #output
  </code></pre>
  
  <p>but when I run my xp_cmdshell, I just get null.  Shouldn't I be getting 1 or 0?</p>
  
  <p>Thanks</p>