MSSQLCity.Com - All about MS SQL
     
About Us  
SSWUG Articles  
Articles  
FAQ  
Administration  
Backup/Restore  
Connectivity  
Development  
General  
Installation  
OLAP  
Replication  
Transfer/move  
Trouble  
SQL 6.5  
Scripts  
Tips  
Test Exams  
Advertise  
Download  
History  
Search  
Traffic  
Related Links  
     
Your button logo
Add to Favorites
 
     
 


How do I execute an operating-system command via Transact-SQL?

Answer:

You can use the xp_cmdshell extended stored procedure to execute a given command string as an operating-system command shell and return any output as rows of text.

This is the syntax of the xp_cmdshell:

xp_cmdshell {'command_string'} [, no_output]

where

'command_string' is varchar(255) or nvarchar(4000), with no default.
no_output - when used no output will be returned.

When executing xp_cmdshell with the Windows 9x operating systems, the return code will always be 0.

Executing this xp_cmdshell statement sends the 'Hello' message to JOHN:

EXEC master..xp_cmdshell "net send JOHN 'Hello'"

See SQL BOL for more information about the xp_cmdshell extended stored procedure.


 

 
Visit The SQL Server Worldwide User's Group for all the latest news and information about SQL Server, Oracle, DB2 and XML for developers and administrators.

(c) 1997, 2010 Bits on the Wire, Inc