Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need help improving small vbs application

Posted on 2004-08-17
4
862 Views
Last Modified: 2010-05-18
I am using the following code to run ping and tracert commands from a browser. Thanks to   DexStar for the code. This works great, but it is pretty slow to respond, since it waits to complete the operation before painting the screen. Can this be modified to paint line-by-line results as they occur in order to speed up the process?

=================
<%@ LANGUAGE="VBSCRIPT" %>
<%
     Dim WshShell : Set WshShell = Server.CreateObject("WScript.Shell")
     
     ' Turn on Page Buffering for better results
     Response.Buffer = True

     Sub ExecCMD( strExec, strTitle )
          Dim proc, n

          ' Write the title, and send it to the browser
          Response.Write "<H1>" & strTitle & "</H1>"
          Response.Flush

          ' Execute the command and wait for it to finish
          Set proc = WshShell.Exec( strExec )
          Do While proc.Status = 0
               ' Anyone know a better way to wait?  WScript.Sleep doesn't work in ASP
               n = n + 1
          Loop

          ' Write the results, and send it to the browser
          Response.Write "<pre>" & proc.StdOut.ReadAll & "</pre>"
          Response.Flush
     End Sub
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Test Results</TITLE>
</HEAD>
<BODY>
<%
     Dim strIP : strIP = Request.QueryString("IP")
     
   If ( strIP & "" <> "" ) Then
          If ( InStr(strIP, " ") = 0 ) Then
               ExecCMD "cmd /c ping " & strIP, "Ping Results"
               ExecCMD "cmd /c tracert " & strIP, "Trace Route Results"
          Else
               Response.Write "Bad H4x0r, No Ping Flood!"
          End If
     Else
          Response.Write "No IP provided!"
     End If
%>
</BODY>
</HTML>
===============
0
Comment
Question by:VAN
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 11824908
@Van:

Try the code that I posted below.  It should fix your issue with the delayed output.  I know it will for sure send the results to the browser as they happen, but I'm not sure if the browser will render them until it gets the </pre> tag.  If not, we might have to tweak it a little.  Let me know what you find out.

-D*

===

<%@ LANGUAGE="VBSCRIPT" %>
<%
      Dim WshShell : Set WshShell = Server.CreateObject("WScript.Shell")
      
      ' Turn on Page Buffering for better results
      Response.Buffer = True

      Sub ExecCMD( strExec, strTitle )
            Dim objProc, objOutput

            ' Write the title, and send it to the browser
            Response.Write "<H1>" & strTitle & "</H1>" & vbNewLine
            Response.Flush

            ' Execute the command and wait for it to finish
            Set objProc = WshShell.Exec( strExec )
            Set objOutput = objProc.StdOut
            Response.Write "<pre>"
            Do While objProc.Status = 0
                  ' Read each line of output so far
                  Do While Not objOutput.AtEndOfStream
                        Response.Write objOutput.ReadLine
                  Loop
                  ' Send it to the browser
                  Response.Flush
            Loop

            ' Write rest of the results
            Response.Write objOutput.ReadAll
            Response.Write "</pre>" & vbNewLine
            Response.Flush
      End Sub
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Test Results</TITLE>
</HEAD>
<BODY>
<%
      Dim strIP : strIP = Request.QueryString("IP")
      
      If ( strIP & "" <> "" ) Then
            If ( InStr(strIP, " ") = 0 ) Then
                  ExecCMD "cmd /c ping " & strIP, "Ping Results"
                  ExecCMD "cmd /c tracert " & strIP, "Trace Route Results"
            Else
                  Response.Write "Bad H4x0r, No Ping Flood!"
            End If
      Else
            Response.Write "No IP provided!"
      End If
%>
</BODY>
</HTML>
0
 
LVL 1

Author Comment

by:VAN
ID: 11825279
Thanks for the reply, Dex, but this is giving the ame results. It waits until it has all data before printing it to the screen.
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 500 total points
ID: 11825351
This is.  It sends each line with it's own <pre> </pre> tags, so the browser should be able to render each line as it comes in.

===

<%@ LANGUAGE="VBSCRIPT" %>
<%
      Dim WshShell : Set WshShell = Server.CreateObject("WScript.Shell")
      
      ' Turn on Page Buffering for better results
      Response.Buffer = True
      
      Sub ShowOutput( strOutput )
            Response.Write "<pre>" & strOutput & "</pre>" & vbNewLine
            Response.Flush
      End Sub

      Sub ExecCMD( strExec, strTitle )
            Dim objProc, objOutput

            ' Write the title, and send it to the browser
            Response.Write "<h1>" & strTitle & "</h1>" & vbNewLine
            Response.Flush

            ' Execute the command and wait for it to finish
            Set objProc = WshShell.Exec( strExec )
            Set objOutput = objProc.StdOut
            Do While objProc.Status = 0
                  ' Write each line of output so far
                  Do While Not objOutput.AtEndOfStream
                        ShowOutput objOutput.ReadLine
                  Loop
            Loop

            ' Write rest of the results
            ShowOutput objOutput.ReadAll
      End Sub
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Test Results</TITLE>
</HEAD>
<BODY>
<%
      Dim strIP : strIP = Request.QueryString("IP")
      
      If ( strIP & "" <> "" ) Then
            If ( InStr(strIP, " ") = 0 ) Then
                  ExecCMD "cmd /c ping " & strIP, "Ping Results"
                  ExecCMD "cmd /c tracert " & strIP, "Trace Route Results"
            Else
                  Response.Write "Bad H4x0r, No Ping Flood!"
            End If
      Else
            Response.Write "No IP provided!"
      End If
%>
</BODY>
</HTML>
0
 
LVL 1

Author Comment

by:VAN
ID: 11825483
That's it! Thanks, Dex!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question