Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xp_cmdshell running async? 1

Status
Not open for further replies.

gbaughma

IS-IT--Management
Staff member
Nov 21, 2003
4,772
US
I have a stored procedure that calls a VBScript file after creating some XML files to do an import into our accounting system.

However, the web page that calls that stored procedure waits until the procedure is returned from before continuing.

Is there a way in my stored procedure to call the vbscript file and let it "do it's thing" without waiting for it to finish, so that control can be returned to my website?

TIA!



Just my 2¢

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
[0] To emulate asynchroneity, you can do it like this: instead of calling the functional vbs (functional.vbs, say) directly, you call the vbs through a fixed caller vbscript (caller.vbs, say) which uses the same command line but called functional.vbs through wshshell object, hidden and asychronous that the vbs engine recognizes. The child process (functional.vbs) will then be let free to process and the caller vbs once finish the asynchronous wshshell.run call will return the control to the xp_cmdshell.

[1] Suppose you have some command like this in the sp. scmd is quite arbitrary here, modify it to suit your need.
[tt]
declare @scmd sysname
set @scmd='c:\windows\system32\cscript.exe //nologo [blue]c:\xyz\functional.vbs[/blue]'
exec xp_cmdshell @scmd, 'no_output'
go
[/tt]
[2] The you construct a vbscript (caller.vbs) to do what is meant by the @scmd, say in the same location, c:\xyz\caller.vbs. This vbs can be made one-liner, if so desired.
[tt]
[blue]'this is c:\xyz\caller.vbs[/blue]
dim scmd
scmd='c:\windows\system32\cscript.exe //nologo [blue]c:\xyz\functional.vbs[/blue]'
createobject("wscript.shell").run scmd[blue],0,false[/blue] 'hidden and asynchronous
[/tt]
[2.1] The xp_cmdshell now looks like this.
[tt]
declare @scmd sysname
set @scmd='c:\windows\system32\cscript.exe //nologo [blue]c:\xyz\caller.vbs[/blue]'
exec xp_cmdshell @scmd, 'no_output'
go
[/tt]
[3] Then the sp xp_cmdshell part will now execute quite asynchronously, leaving the functional.vbs doing its job and the sp continues to execute next lines.
 
  • Thread starter
  • Moderator
  • #3
Double-quotes in the VBS... but overall, awesome. :)


Just my 2¢

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
  • Thread starter
  • Moderator
  • #5
That method worked great, by the way. Thank you again, tsuji.



Just my 2¢

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top