Link to home
Start Free TrialLog in
Avatar of grotesmurf2
grotesmurf2

asked on

xp_cmdshell with variable

this is my script:

BEGIN
DECLARE @ret int
DECLARE @instr sysname
SET @instr='dir'
EXEC @ret = xp_cmdshell @instr
UPDATE dirresults SET result=@ret WHERE id=20
END


the problem is, result always stays empty (even if i change my instruction to something that doesn't exist)

my questions:
a)how can I get the result (0 or 1)?
b) how can I get the result of the dir command (e.g. the directory listing)?
Avatar of ShogunWade
ShogunWade

? why have you declared your parameter as a sysname as opposed to varchar ?
SOLUTION
Avatar of Dishan Fernando
Dishan Fernando
Flag of Malaysia 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
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
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
SOLUTION
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
thank you all...

it must be an authority issue I guess. strange I don't get 0 or 1 as output, but just an empty string... sigh...