title: Get Results from XP_CMDSHELL
body: <p>I have been searching the web some and it seems like the only way to get the results from XP_CMDSHELL is to store them into a temp table.  Is there really no easier way?</p>
  
  <p>From Experts Exchange:</p>
  
  <blockquote>
    <p>No, xp_cmdshell will not return any information from the exe. and you have to use the following 
    syntax if you are not in the master database to run it.  master..xp_cmdshell.  You will have to 
    give your user permission to execute this procedure in the master database.  You will have to have 
    your exe insert the information its self because it can not return information to the process that 
    called it. </p>
  </blockquote>
  
  <p>And...</p>
  
  <p>While @result only gets the return value from xp_cmdshell, you may be able to capture the results 
  of the command by inserting directly into a table... something like this:</p>
  
  <p>ymmv...</p>
  
  <pre><code>set nocount on
  declare  @filepath   varchar(255),
           @cmd        varchar(255),
           @rc         int
  
  select   @filepath = 'c:\temp\'         
  select   @cmd      = 'dir ' + @filepath + '~*.tmp'
  
  create table #output (output varchar(255) null)
  insert #output exec @rc = master..xp_cmdshell @cmd
  select * from #output where output is not null
  drop table #output
  </code></pre>