|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
execute a .bat from .asp
Originally posted by : shiju (webshiju@hotmail.com)i'm trying to execute a .bat file from .asp file on Windows2000 system.i tried the following code:when i use command line above .bat is working perfectly fine. but when i run above .asp it is giving "not working" message..i tried cahnging the file permission still no luck. can u tell me what is should do executing the .bat from .asp..thanks
|
|
#2
|
|||
|
|||
|
Originally posted by : Dave Wood (obsidian@panix.com)You know, Microsoft does an amazing amount of work to document their products. Unfortunately, all of it is really _bad_ work. Their documentation is the most disorganized and ridiculous I've seen for any commercial software (and that includes Oracle!) and it's impossible to find out anything really useful - especially about simple, basic stuff like this.I did manage this today; it wasn't easy. 1) Get the latest version of the scripting host and install it (5.6 as of this writing). http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml2) Use Exec instead of Run. Hence
im Shell Set Shell = Server.CreateObject("WScript.Shell") Dim sexecSet sexec = Shell.Exec("c: estupdate.bat")3) Make sure you read out the stdout and stderr streams. Things don't seem to happen unless you do that.Dim soutsout = sexec.stdout.readAllDim serrserr = sexec.stderr.readAll' (You might need to do this repetitively, though I didn't) ' I take a look at it in my page here:Response.write ""Response.write "ReadAll: " & resultResponse.write "stderr: " & serr4) You're still executing asyncronously. You'll need to do a busy wait loop for your script to finish - since there's no accessible sleep function in the ASP context and no "finished" event on exec. ROTFLMFAO. Go ahead and get yourself a delay timer activeX control. Fortunately someone wrote one and you can download the DLL:http://www.aspalliance.com/stevesmith/articles/sleeptimer.aspOf course, the poor bastard doesn't tell you how to actually USE it...regsvr32 c:whereveryouput imer.dllAnd thenDim timerset timer = Server.CreateObject("Timer.Sleep")Do While sexec.Status 1 timer.DoSleep(100)LoopOnce sexec.Status becomes 1, execution is complete, and sexec.ExitCode becomes valid.****ing brilliant, eh? Now, what the hell are you doing writing ASP code anyway? Let me give you a hint: you can do all this with one line of PHP code, and you won't need to get 0wned by Nimda before you can install all your IIS patches, either. Take my advice, take your Win2K CD, go to the microwave, and give it about 2 minutes on high. Then go buy RedHat. You can thank me later.------------shiju at 1/29/2002 11:16:43 AMi'm trying to execute a .bat file from .asp file on Windows2000 system.i tried the following code:when i use command line above .bat is working perfectly fine. but when i run above .asp it is giving "not working" message..i tried cahnging the file permission still no luck. can u tell me what is should do executing the .bat from .asp..thanks |
|
#3
|
|||
|
|||
|
Originally posted by : Dave Wood (obsidian@panix.com)Oh yeah... did eventually manage to get Run to work also, so it's a bit simpler if you don't need access to your program's output or input:dim exitcodeexitcode = script.run("your command",10,true) The last arg is true to wait until execution is complete, and get the proper exit code...------------Dave Wood at 2/5/2002 10:35:13 PMYou know, Microsoft does an amazing amount of work to document their products. Unfortunately, all of it is really _bad_ work. Their documentation is the most disorganized and ridiculous I've seen for any commercial software (and that includes Oracle!) and it's impossible to find out anything really useful - especially about simple, basic stuff like this.I did manage this today; it wasn't easy. 1) Get the latest version of the scripting host and install it (5.6 as of this writing). http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml2) Use Exec instead of Run. Hence
im Shell Set Shell = Server.CreateObject("WScript.Shell") Dim sexecSet sexec = Shell.Exec("c: estupdate.bat")3) Make sure you read out the stdout and stderr streams. Things don't seem to happen unless you do that.Dim soutsout = sexec.stdout.readAllDim serrserr = sexec.stderr.readAll' (You might need to do this repetitively, though I didn't) ' I take a look at it in my page here:Response.write ""Response.write "ReadAll: " & resultResponse.write "stderr: " & serr4) You're still executing asyncronously. You'll need to do a busy wait loop for your script to finish - since there's no accessible sleep function in the ASP context and no "finished" event on exec. ROTFLMFAO. Go ahead and get yourself a delay timer activeX control. Fortunately someone wrote one and you can download the DLL:http://www.aspalliance.com/stevesmith/articles/sleeptimer.aspOf course, the poor bastard doesn't tell you how to actually USE it...regsvr32 c:whereveryouput imer.dllAnd thenDim timerset timer = Server.CreateObject("Timer.Sleep")Do While sexec.Status 1 timer.DoSleep(100)LoopOnce sexec.Status becomes 1, execution is complete, and sexec.ExitCode becomes valid.****ing brilliant, eh? Now, what the hell are you doing writing ASP code anyway? Let me give you a hint: you can do all this with one line of PHP code, and you won't need to get 0wned by Nimda before you can install all your IIS patches, either. Take my advice, take your Win2K CD, go to the microwave, and give it about 2 minutes on high. Then go buy RedHat. You can thank me later.------------shiju at 1/29/2002 11:16:43 AMi'm trying to execute a .bat file from .asp file on Windows2000 system.i tried the following code:when i use command line above .bat is working perfectly fine. but when i run above .asp it is giving "not working" message..i tried cahnging the file permission still no luck. can u tell me what is should do executing the .bat from .asp..thanks |
|
#4
|
|||
|
|||
|
Originally posted by : Shiju Rajan (webshiju@hotmail.com)Hi Dave, Thanks for your help..It is very useful information you wrote here...You know my WScript.Run start working after i install the asp.net on IIS ... i really don't know how it is start working...i'm going to try your code now.... and i'll try that timer control also.becuase i need to make sure that the .bat file is finishing successfully and the other users are not distrupting the execution... i'm planning to have an application variable initialized in asp for preventing the simultanious execution of .bat... what you suggest on that?you may write an article regarding same topic and publish in some site then that would be really helpful for the other programmers..I really appreciate your help..Thanks againGod bless! ------------Dave Wood at 2/5/2002 10:51:01 PMOh yeah... did eventually manage to get Run to work also, so it's a bit simpler if you don't need access to your program's output or input:dim exitcodeexitcode = script.run("your command",10,true) The last arg is true to wait until execution is complete, and get the proper exit code...------------Dave Wood at 2/5/2002 10:35:13 PMYou know, Microsoft does an amazing amount of work to document their products. Unfortunately, all of it is really _bad_ work. Their documentation is the most disorganized and ridiculous I've seen for any commercial software (and that includes Oracle!) and it's impossible to find out anything really useful - especially about simple, basic stuff like this.I did manage this today; it wasn't easy. 1) Get the latest version of the scripting host and install it (5.6 as of this writing). http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml2) Use Exec instead of Run. Hence
im Shell Set Shell = Server.CreateObject("WScript.Shell") Dim sexecSet sexec = Shell.Exec("c: estupdate.bat")3) Make sure you read out the stdout and stderr streams. Things don't seem to happen unless you do that.Dim soutsout = sexec.stdout.readAllDim serrserr = sexec.stderr.readAll' (You might need to do this repetitively, though I didn't) ' I take a look at it in my page here:Response.write ""Response.write "ReadAll: " & resultResponse.write "stderr: " & serr4) You're still executing asyncronously. You'll need to do a busy wait loop for your script to finish - since there's no accessible sleep function in the ASP context and no "finished" event on exec. ROTFLMFAO. Go ahead and get yourself a delay timer activeX control. Fortunately someone wrote one and you can download the DLL:http://www.aspalliance.com/stevesmith/articles/sleeptimer.aspOf course, the poor bastard doesn't tell you how to actually USE it...regsvr32 c:whereveryouput imer.dllAnd thenDim timerset timer = Server.CreateObject("Timer.Sleep")Do While sexec.Status 1 timer.DoSleep(100)LoopOnce sexec.Status becomes 1, execution is complete, and sexec.ExitCode becomes valid.****ing brilliant, eh? Now, what the hell are you doing writing ASP code anyway? Let me give you a hint: you can do all this with one line of PHP code, and you won't need to get 0wned by Nimda before you can install all your IIS patches, either. Take my advice, take your Win2K CD, go to the microwave, and give it about 2 minutes on high. Then go buy RedHat. You can thank me later.------------shiju at 1/29/2002 11:16:43 AMi'm trying to execute a .bat file from .asp file on Windows2000 system.i tried the following code:when i use command line above .bat is working perfectly fine. but when i run above .asp it is giving "not working" message..i tried cahnging the file permission still no luck. can u tell me what is should do executing the .bat from .asp..thanks |
|
#5
|
|||
|
|||
|
Originally posted by : David Wood (obsidian@panix.com)"You know my WScript.Run start working after i install the asp.net on IIS ... i really don't know how it is start working..."I assume the asp.net install upgrades your scripting host. "i'm planning to have an application variable initialized in asp for preventing the simultanious execution of .bat... what you suggest on that?"Good idea. I don't know whether or not you'll need to lock the Application object just to set/check your "bat in use" field in order to prevent a race. You might. In which case I hope you have nothing else already setting application fields elsewhere, because you can only lock the whole thing at once. Heh.------------Shiju Rajan at 2/6/2002 5:02:25 AMHi Dave, Thanks for your help..It is very useful information you wrote here...You know my WScript.Run start working after i install the asp.net on IIS ... i really don't know how it is start working...i'm going to try your code now.... and i'll try that timer control also.becuase i need to make sure that the .bat file is finishing successfully and the other users are not distrupting the execution... i'm planning to have an application variable initialized in asp for preventing the simultanious execution of .bat... what you suggest on that?you may write an article regarding same topic and publish in some site then that would be really helpful for the other programmers..I really appreciate your help..Thanks againGod bless! ------------Dave Wood at 2/5/2002 10:51:01 PMOh yeah... did eventually manage to get Run to work also, so it's a bit simpler if you don't need access to your program's output or input:dim exitcodeexitcode = script.run("your command",10,true) The last arg is true to wait until execution is complete, and get the proper exit code...------------Dave Wood at 2/5/2002 10:35:13 PMYou know, Microsoft does an amazing amount of work to document their products. Unfortunately, all of it is really _bad_ work. Their documentation is the most disorganized and ridiculous I've seen for any commercial software (and that includes Oracle!) and it's impossible to find out anything really useful - especially about simple, basic stuff like this.I did manage this today; it wasn't easy. 1) Get the latest version of the scripting host and install it (5.6 as of this writing). http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml2) Use Exec instead of Run. Hence
im Shell Set Shell = Server.CreateObject("WScript.Shell") Dim sexecSet sexec = Shell.Exec("c: estupdate.bat")3) Make sure you read out the stdout and stderr streams. Things don't seem to happen unless you do that.Dim soutsout = sexec.stdout.readAllDim serrserr = sexec.stderr.readAll' (You might need to do this repetitively, though I didn't) ' I take a look at it in my page here:Response.write ""Response.write "ReadAll: " & resultResponse.write "stderr: " & serr4) You're still executing asyncronously. You'll need to do a busy wait loop for your script to finish - since there's no accessible sleep function in the ASP context and no "finished" event on exec. ROTFLMFAO. Go ahead and get yourself a delay timer activeX control. Fortunately someone wrote one and you can download the DLL:http://www.aspalliance.com/stevesmith/articles/sleeptimer.aspOf course, the poor bastard doesn't tell you how to actually USE it...regsvr32 c:whereveryouput imer.dllAnd thenDim timerset timer = Server.CreateObject("Timer.Sleep")Do While sexec.Status 1 timer.DoSleep(100)LoopOnce sexec.Status becomes 1, execution is complete, and sexec.ExitCode becomes valid.****ing brilliant, eh? Now, what the hell are you doing writing ASP code anyway? Let me give you a hint: you can do all this with one line of PHP code, and you won't need to get 0wned by Nimda before you can install all your IIS patches, either. Take my advice, take your Win2K CD, go to the microwave, and give it about 2 minutes on high. Then go buy RedHat. You can thank me later.------------shiju at 1/29/2002 11:16:43 AMi'm trying to execute a .bat file from .asp file on Windows2000 system.i tried the following code:when i use command line above .bat is working perfectly fine. but when i run above .asp it is giving "not working" message..i tried cahnging the file permission still no luck. can u tell me what is should do executing the .bat from .asp..thanks |
|
#6
|
|||
|
|||
|
Originally posted by : Shiju (webshiju@hotmail.com)Yes David,i'm planning to do the same action.i'll lock the application object before .bat execution and after the use i'll unlock the variable.so that action should work fine.Thanks for the help..------------David Wood at 2/6/2002 9:32:42 AM"You know my WScript.Run start working after i install the asp.net on IIS ... i really don't know how it is start working..."I assume the asp.net install upgrades your scripting host. "i'm planning to have an application variable initialized in asp for preventing the simultanious execution of .bat... what you suggest on that?"Good idea. I don't know whether or not you'll need to lock the Application object just to set/check your "bat in use" field in order to prevent a race. You might. In which case I hope you have nothing else already setting application fields elsewhere, because you can only lock the whole thing at once. Heh.------------Shiju Rajan at 2/6/2002 5:02:25 AMHi Dave, Thanks for your help..It is very useful information you wrote here...You know my WScript.Run start working after i install the asp.net on IIS ... i really don't know how it is start working...i'm going to try your code now.... and i'll try that timer control also.becuase i need to make sure that the .bat file is finishing successfully and the other users are not distrupting the execution... i'm planning to have an application variable initialized in asp for preventing the simultanious execution of .bat... what you suggest on that?you may write an article regarding same topic and publish in some site then that would be really helpful for the other programmers..I really appreciate your help..Thanks againGod bless! ------------Dave Wood at 2/5/2002 10:51:01 PMOh yeah... did eventually manage to get Run to work also, so it's a bit simpler if you don't need access to your program's output or input:dim exitcodeexitcode = script.run("your command",10,true) The last arg is true to wait until execution is complete, and get the proper exit code...------------Dave Wood at 2/5/2002 10:35:13 PMYou know, Microsoft does an amazing amount of work to document their products. Unfortunately, all of it is really _bad_ work. Their documentation is the most disorganized and ridiculous I've seen for any commercial software (and that includes Oracle!) and it's impossible to find out anything really useful - especially about simple, basic stuff like this.I did manage this today; it wasn't easy. 1) Get the latest version of the scripting host and install it (5.6 as of this writing). http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml2) Use Exec instead of Run. Hence
im Shell Set Shell = Server.CreateObject("WScript.Shell") Dim sexecSet sexec = Shell.Exec("c: estupdate.bat")3) Make sure you read out the stdout and stderr streams. Things don't seem to happen unless you do that.Dim soutsout = sexec.stdout.readAllDim serrserr = sexec.stderr.readAll' (You might need to do this repetitively, though I didn't) ' I take a look at it in my page here:Response.write ""Response.write "ReadAll: " & resultResponse.write "stderr: " & serr4) You're still executing asyncronously. You'll need to do a busy wait loop for your script to finish - since there's no accessible sleep function in the ASP context and no "finished" event on exec. ROTFLMFAO. Go ahead and get yourself a delay timer activeX control. Fortunately someone wrote one and you can download the DLL:http://www.aspalliance.com/stevesmith/articles/sleeptimer.aspOf course, the poor bastard doesn't tell you how to actually USE it...regsvr32 c:whereveryouput imer.dllAnd thenDim timerset timer = Server.CreateObject("Timer.Sleep")Do While sexec.Status 1 timer.DoSleep(100)LoopOnce sexec.Status becomes 1, execution is complete, and sexec.ExitCode becomes valid.****ing brilliant, eh? Now, what the hell are you doing writing ASP code anyway? Let me give you a hint: you can do all this with one line of PHP code, and you won't need to get 0wned by Nimda before you can install all your IIS patches, either. Take my advice, take your Win2K CD, go to the microwave, and give it about 2 minutes on high. Then go buy RedHat. You can thank me later.------------shiju at 1/29/2002 11:16:43 AMi'm trying to execute a .bat file from .asp file on Windows2000 system.i tried the following code:when i use command line above .bat is working perfectly fine. but when i run above .asp it is giving "not working" message..i tried cahnging the file permission still no luck. can u tell me what is should do executing the .bat from .asp..thanks |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > execute a .bat from .asp |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|