Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » SQL Anywhere Server - SQL Reference » System procedures » Alphabetical list of system procedures

xp_cmdshell system procedure

Carries out an operating system command from a procedure.

Syntax
xp_cmdshell( 
command 
[, redir_output | 'no_output' ]
)
Parameters
  • command

    Use this VARCHAR(8000) parameter to specify a system command. The default is NULL.

  • redir_output

    Use this optional CHAR(254) parameter to specify whether to display output in a command window. The default behavior is to display output in a command window. If you specify 'no_output', output is not displayed in a command window. The default value is ' '.

Returns

This function returns an INTEGER exit code.

Remarks

xp_cmdshell executes a system command and then returns control to the calling environment. The value returned by xp_cmdshell is the exit code from the executed shell process. The return value is 2 if an error occurs when the child process is started.

The second parameter affects only command line applications on Windows operating systems. For Unix, no command window appears, regardless of the setting for the second parameter.

Use the sa_enable_auditing_type and sa_disable_auditing_type system procedures to enable and disable auditing of the xp_cmdshell system procedure (using the xp_cmdshell type). When auditing is enabled for xp_cmdshell, all invocations of the xp_cmdshell procedure are logged to the audit log, including the user that executed the procedure, and the parameters that were passed to the procedure.

Privileges

You must have EXECUTE privilege on the system procedure, as well as the SERVER OPERATOR system privilege.

Example

The following statement lists the files in the current directory in the file c:\temp.txt:

CALL xp_cmdshell( 'dir > c:\\temp.txt' );

The following statement carries out the same operation, but does so without displaying a Command window.

CALL xp_cmdshell( 'dir > c:\\temp.txt', 'no_output' );