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
 SQL Server Development (2000)
 Exe files

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-07-15 : 07:53:29
Mala writes "Hi,

How can I execute .exe and batch files in server from stored procedure. I tried doing it from xp_cmdshell. But it always give message as 'exec' or 'run' is not supported.

Regards,
Mala"

Kristen
Test

22859 Posts

Posted - 2005-07-15 : 08:00:25
Does

EXEC master.dbo.xp_cmdshell 'DIR C:\'

give you any output?

Kristen
Go to Top of Page

Mala
Starting Member

26 Posts

Posted - 2005-07-19 : 02:50:11
Yes. It displays all the folder name and time stamp under C. But using the xp_xmdshell I am unable to execute .exe or batch files.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-07-19 : 02:58:54
quote:
Originally posted by Mala

Yes. It displays all the folder name and time stamp under C. But using the xp_xmdshell I am unable to execute .exe or batch files.



what .exe files are you trying to execute? Keep in mind that you cannot run apps that have a graphical frontend or require user input (like clicking on buttons).



-ec
Go to Top of Page

Mala
Starting Member

26 Posts

Posted - 2005-07-19 : 04:15:49
I am trying to run an exe file compied from C++. No it has not graphical interface or user intput. But on clicking/execution it reads data from someother test file. When I just click this exec files directly it works. But form XP_cmdshell it give message as 'exec' or 'run' command not allowed in xp_cmdshell
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-07-19 : 05:51:05
Access rights!!!

When running via xp_cmdshell, you are running via a different 'account', from when you double-click direct on the exe. Change QA account, or change priviliges of QA account or change protection on the EXE.
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-07-19 : 06:01:34
remove the word 'exec' or 'run' in your command, just type in the exe name or better yet,
post the command you used for xp_cmdshell

quote:
Originally posted by Mala

I am trying to run an exe file compied from C++. No it has not graphical interface or user intput. But on clicking/execution it reads data from someother test file. When I just click this exec files directly it works. But form XP_cmdshell it give message as 'exec' or 'run' command not allowed in xp_cmdshell



--------------------
keeping it simple...
Go to Top of Page

Mala
Starting Member

26 Posts

Posted - 2005-07-19 : 22:16:01
Hi I am runnig from windows authentication and as admin. So got full access to all the files.

When I execute "exec master..xp_cmdshell 'dir c:\mit\website\bos_Et\test\*.exe' " I get results. But if I execute " exec master..xp_cmdshell 'exec c:\mit\website\bos_Et\test\*.exe' " I will get resulat as :
'exec' is not recognized as an internal or external command,
operable program or batch file.
NULL

The same with run also.
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-07-19 : 22:28:38
as i suggested remove the exec in the cmdshell and specify name of exe file

exec master..xp_cmdshell 'exec c:\mit\website\bos_Et\test\nameofexefile.exe'

--------------------
keeping it simple...
Go to Top of Page

Mala
Starting Member

26 Posts

Posted - 2005-07-19 : 23:03:11
Thanks. It works. But I need to do otherway round.
If I execute " exec master..xp_cmdshell 'c:\mit\website\bos_Et\test\rs232.exe' ", though it won't give any error, it was not actually executing the exe file (action not taken place)

so I created a batch file as :
cd c:\mit\website\bos_et\test
rs232.exe

and executing it from QA "exec master..xp_cmdshell 'c:\mit\website\bos_Et\test\rs232.bat' "
But I am not sure when I directly give exe file why it is not executing.

Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-07-19 : 23:17:47
to clarify, if it's a batch file, it executes the action you set, but
if it's the exe file, it doesn't execute the way you want it to do?

can you modify your exe to capture success or failure processing and save that to a text file so you can review where the failure occured?

sql can only check if the command you executed succeeded or failed, any failures within the exe file itself will not be captured.

--------------------
keeping it simple...
Go to Top of Page

Mala
Starting Member

26 Posts

Posted - 2005-07-19 : 23:22:04
There is no prob with exe file. When I execute it directly and through batch file it works. Only when I directly execute from xp_smdshell no action will take place.
Go to Top of Page

Mala
Starting Member

26 Posts

Posted - 2005-07-20 : 03:12:28
Hi,

I am facing typical problem. I am execute the bacth file.
This works
1] exec master..xp_cmdshell 'c:\mit\website\bos_et\test\rs232.bat'
2] exec Sp_Testexec 'c:\mit\website\bos_et\test' (rs232.bat hardcoded in sp)

the same sp I am calling from asp and sp is getting executed. (I have given an insert command for no error). But whatever the action bat file should trigger is not happening.
Go to Top of Page
   

- Advertisement -