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 2008 Forums
 Transact-SQL (2008)
 EXEC XP_CMDSHELL 'exe'

Author  Topic 

Gigabyte
Starting Member

30 Posts

Posted - 2012-11-09 : 01:09:13
exec xp_cmdshell 'exe file path'

This is running forever ...any help I could get??

Thanks in advance.


GIGABYTE+

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-09 : 06:56:57
If the executable that you are running displays a window or is expecting any user input, it will not terminate - you will need to kill it from the task manager.

If that is not the case: are you able to run the exe from a command window successfully? If you are, then do some experimentation - start with a simple example: exec xp_cmdshell 'dir c:\' and see if that works for you.
Go to Top of Page

Gigabyte
Starting Member

30 Posts

Posted - 2012-11-09 : 07:20:21
I am using this and it is running for ever ..

exec xp_cmdshell 'C:\Windows\System32\calc.exe'

Also there will be no use if I run this and stop it using task manager.

Is it possible to open exe program and stop the query execution automatically.


GIGABYTE+
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-09 : 07:27:46
quote:
Is it possible to open exe program and stop the query execution automatically.

This is not possible. xp_cmdshell operates synchronously, so control is not returned to the T-SQL session until the command is completed.

When you use xp_cmdshell, commands are run in the background. You would not see the calculator window on your screen. You can see calc.exe in task manager (be sure to check the box that says "Show processes from all users" in the task manager).

The bottom line is that xp_cmdshell should NOT be used to run programs that require user input to proceed or require user input to terminate.
Go to Top of Page

Gigabyte
Starting Member

30 Posts

Posted - 2012-11-09 : 07:38:03
Thank you so much Sunitabeck.

Thanks for quick responses.

GIGABYTE+
Go to Top of Page
   

- Advertisement -