Link to home
Start Free TrialLog in
Avatar of TimFCollins
TimFCollins

asked on

How can I configure the xp_cmdshell command to execute a file through the command prompt including passing variables?

Hello,

I am trying to use the xp_cmdshell sp in SQL Server 2000 to execute an exe file that requires variables.  I can get it to execute the file but it won't add the variables.

I am trying to call sendmail.exe.  When in a command window I can type:
c:\sendmail.exe -t to@test.com -f from@test.com -s test -m 10.100.1.1

and that works fine.  However, when I put it in a SQL Server stored procedure:

set @cmdtest = 'c:\sendmail.exe -t to@test.com -f from@test.com -s test -m 10.100.1.1'
exec xp_cmdshell @cmdtest

when i run this i get a result back that is the same as entering 'c:\sendmail.exe 'in a command window.  How can I get SQL Server to recognize the rest of the string that I'm passing to xp_cmdshell?

Thanks in Advance,
Tim F.
SOLUTION
Avatar of MohammedU
MohammedU
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
Avatar of TimFCollins
TimFCollins

ASKER

Thanks for the quick response.  I tried it with the double quotes like you suggested and also around each parameter and I got back that it is not recognized as an internal or external command, operable file or batch file.  Is there anything else that might make it recognize the string as a whole?

Thanks,
Tim F.
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
ASKER CERTIFIED 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