Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 xp_cmdshell

Author  Topic 

achowe
Starting Member

6 Posts

Posted - 2003-07-14 : 07:39:13
To anyone that can help...

We have a problem when trying to execute an .exe file using xp_cmdshell:

exec master.. xp_cmdshell 'c:\pcplus\refiner.exe'

Query analyzer seems to run the query with no problems, returning a value NULL but nothing else. It doesnt seem to run the file but doesnt return any errors either..any ideas as to why?????

Thanks



X002548
Not Just a Number

15586 Posts

Posted - 2003-07-14 : 09:58:38
Because xp_cmdshell does it's job, and does not fail.

It's an independant thread that does not "know" the outcome of the called executable.


That's not really true...it's just limited...

You need to determine another manner to determine if the called application is successful or not.

What is refiner.exe suppose to do?

And is it on the server's C drive?



Brett

8-)

Edited by - x002548 on 07/14/2003 11:02:41
Go to Top of Page

achowe
Starting Member

6 Posts

Posted - 2003-07-14 : 10:23:29
We have tried it with a number of applications, all of which are on the c: of the server, i.e. notepad, calculator etc...

but it's as if SQL server doesnt know when the application has finished its process...theres no indication from sql server that the program has been been either executed or terminated......

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-07-14 : 11:01:39
From BOL
quote:

xp_cmdshell operates synchronously.

Control is not returned until the command shell command completes.



So if it's in a sproc, you'll know when it's done, because the next line of code after the call will indicate that it's done


Try the following:


master..xp_cmdshell 'dir c:\*.*'
SELECT @@Error AS RC
GO
master..xp_cmdshell 'dir c:\dfgsdfg\*.*'
SELECT @@Error AS RC
GO
master..xp_cmdshell 'xxx c:\dfgsdfg\*.*'
SELECT @@Error AS RC
GO


Even though there are 3 different types, they all return 0 to @@Error

Now check out:


DECLARE @RC Int
EXEC @Rc = master..xp_cmdshell 'dir c:\*.*'
SELECT @RC AS RC
GO
DECLARE @RC Int
EXEC @rc = master..xp_cmdshell 'dir c:\dfgsdfg\*.*'
SELECT @RC AS RC
GO
DECLARE @RC Int
EXEC @rc = master..xp_cmdshell 'xxx c:\dfgsdfg\*.*'
SELECT @RC AS RC
GO



The first RC is 0 but the other 2 are 1. Doesn't tell you that dir executed successfully but didn't find the directory. And unlike the 3rd, it's not even a valid "command"

HTH



Brett

8-)
Go to Top of Page

achowe
Starting Member

6 Posts

Posted - 2003-07-15 : 03:30:58
So if the next piece of code in the SPROC is executed the app ran successfully.....it just seems strange that theres no indication of this other than the next transaction executing.......



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-07-15 : 13:52:18
It's going to execute regardless...

Did you try the examples?



Brett

8-)
Go to Top of Page
   

- Advertisement -