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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Value from .Bat File 2

Status
Not open for further replies.

sweevo

Programmer
Jan 30, 2002
182
0
0
GB
Hello,

If I shell out to a .bat file, is it possible to return any output back to the ASP directly, or do I need to write the output to a text file, then read that back in?

At the moment I have the following:

Code:
Dim objShell, iReturn
set objShell = server.createobject("wscript.shell")
iReturn = objShell.run(request.servervariables("APPL_PHYSICAL_PATH") & "bat_test.bat > " & request.servervariables("APPL_PHYSICAL_PATH") & "bat_output.txt", 0, True)
Response.Write iReturn 'Zero if successful
set objShell = nothing

It's not a big problem if I have to subsequently read in the output txt file, I was just wondering if there was another way.

Thanks
 
The easiest option would probably be to use ASPExec from ServerObjects. That object lets you execute things locally on the server and receive the response back from the executed script.

The other option is to use WSHShell.Exec to execute your file. It is a little limited in some ways (sorry, haven't used it in a while, can't remember), but you can bind directly to the StdIn and StdOut pipes for whatever you execute, technically giving you the capability of asynchronously receiving the data. Dug through some of my scripts and found an example of pinging with Asynchronous output (as well as a commented out pseudo-synchronous part):
Code:
<%
Dim WshShell, pngExec, strComputer
Set WshShell = Server.CreateObject("wscript.shell")
strComputer = "localhost"
'Ping Computer
set pngExec = WshShell.exec("ping -n 4 " & strComputer)

Response.Write "<pre>"
do until pngExec.StdOut.AtEndOfStream
	Response.Write pngExec.StdOut.Read(1)
	Response.Flush
loop
Response.Write "</pre>"

'or if you just want all the output at once:
'Do Until pngExec.Status = 1
'	'sleep or something?
'Loop
'Response.Write "<pre>" & pngExec.StdOut.ReadAll & "</pre>"
%>

Hope this helps,
-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top