Link to home
Start Free TrialLog in
Avatar of LindbakRetail
LindbakRetail

asked on

xp_cmdshell returns null

xp_cmdshell returns null. I have turned on the security option for xp_cmdshell, so no error messages are thrown.
if i run:
exec master..xp_cmdshell 'blabla'
All i get is a recordset with one column and one row containing a null value.
It doesn't matter if i try to run a command text that should not work, like 'hello'. The result is still the same.
Avatar of appari
appari
Flag of India image

try like this, you have to catch xp_cmdshell's return value to see if the command executed succesfully or failed. and the result of the command is returned as a result set.

DECLARE @result int
EXEC @result = xp_cmdshell 'your command'
IF (@result = 0)
   PRINT 'Success'
ELSE
   PRINT 'Failure'
The only thing xp_cmdshell returns is 0 (success) or 1 (failure)

The xp_cmdshell is an external program to SQL Server. It spawns a command window and passes in a string for execution.
Avatar of LindbakRetail
LindbakRetail

ASKER

No, the procedure results in a table containing the output from the command that i was passing. I.e. if I pass the string 'dir c:\' i would get a recordset with one column and with one row for each row of output from the command, in this case what dir outputs.
I run it on another Sql Server 2000 and 2005, and it works. But not on this particular server. What can be wrong?
Are you running it manually, or have it scheduled as a job? If it is a job, does SQLAgent have the necessary permissions on that server?
I'm running it as sa.
Do SA have the same permissions on that server as it does on the other servers? Because one server fails, that makes me believe it is probably a permissions issue.

On that server, is there anything in the application or system event logs?
I found out that Panda Anti Virus was the problem. I disabled the component "TruePrevent" and I started to get some output!
Cool. It had to be something that made that server different than the others.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial