Executes a native operating system command on the host system running the SAP ASE server.
xp_cmdshell command[, no_output] [return_status | no_wait]
xp_cmdshell 'copy C:\log A:\log.0102', no_output
xp_cmdshell 'ls'
xp_cmdshell returns any output, including operating system errors, as rows of text in a single column.
xp_cmdshell is run from the current directory of the XP Server.
The width of the column of returned output is 80 characters. The output is not formatted.
xp_cmdshell cannot perform commands that require interaction with the user, such as “login”.
The user context in which an operating system command is executed via xp_cmdshell is controlled by the value of the xp_cmdshell context configuration parameter. If this parameter is set to 1 (the default), xp_cmdshell restricts permission to users with System Administration privileges at the operating system level. If this parameter is set to 0, xp_cmdshell uses the security context of the operating system account under which the SAP ASE server is running. Therefore, using xp_cmdshell with the xp_cmdshell context configuration parameter set to 0, any user can execute operating system commands using the permissions of the account running the SAP ASE server. This account may have fewer restrictions than the user’s own account.
grant execute on xp_cmdshell to joe
To find out if xp_cmdshell was successful in spawning an external command XP Server, enter the following, where command is the name of the command you ran with xp_cmdshell:
exec @ret = xp_cmdshell command
If xp_cmdshell was successful, exec @ret = xp_cmdshell command returns a value of 0. If xp_cmdshell failed, exec @ret = xp_cmdshell command returns a value of 1.
To find out if the command you ran using xp_cmdshell was itself successful, enter the following, where command is the name of the command you ran with xp_cmdshell:
exec @ret = xp_cmdshell command, return_status
exec @ret = xp_cmdshell command, return_status causes xp_cmdshell to return the actual exit status code of the command. If a failure occurrs and XP Server cannot run the command, xp_cmdshell returns a value of 1. If the command runs successfully, xp_cmdshell returns a value of 0.
If the command was successful, exec @ret = xp_cmdshell command returns a value of 0. If the command failed, exec @ret = xp_cmdshell command returns a value of 1.
Also, the no_output parameter can still be used in combination with return_status, in any order.
create existing table xpoutput ( cmdstr varchar(255) null ) external procedure at "THIS...xp_cmdshell" select cmdstr from xpoutput where cmdstr = "date"
If you do not use cmdstr, you see an error message.
See Remote Procedures as Proxy Tables in the Component Integration Services User’s Guide for more information about results returned from the proxy table.
See also System Administration Guide.
By default, only a system administrator can execute xp_cmdshell. A system administrator can grant execute permission to other users.