As seen in the title, I want to invoke a commandline program, like ping.exe and display it's results incrementally on a webpage using AJAX.
By using the following VB.NET code, I can reroute the output of the ping command to a textbox
1Dim siAs New ProcessStartInfo("cmd.exe")23si.RedirectStandardInput =True45si.RedirectStandardOutput =True67si.UseShellExecute =False89'Start the procses.1011Dim pAs Process = Process.Start(si)1213'Issue the ping command.1415p.StandardInput.WriteLine("ping -n 1 " & klant.connectieGegevens.IpAdres(0))1617'Exit the application.1819p.StandardInput.WriteLine("exit")2021'Read all the output generated from it.2223Dim outputAs String = p.StandardOutput.ReadToEnd()
BUT, the user has to wait untill the control has executed... now... thep.StandardOutput.BaseStream.BeginRead()
command allows me to access the stream assynchronously and add the contents incrementally to a control.
My question is, can I use AJAX to add this output to my webpage without using postbacks, and if so, how?
Thanks for any help you can give me
Hi,
Do it like this if i don't misunderstand you:
<%@. Page Language="VB" %>
<%@. Import Namespace="System.Diagnostics" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim si As New ProcessStartInfo("cmd.exe")
si.RedirectStandardInput = True
si.RedirectStandardOutput = True
si.UseShellExecute = False
'Start the procses.
Dim p As Process = Process.Start(si)
'Issue the ping command.
p.StandardInput.WriteLine("ping -n 1 157.60.114.61")
'Exit the application.
p.StandardInput.WriteLine("exit")
'Read all the output generated from it.
TextBox1.Text = p.StandardOutput.ReadToEnd()End Sub
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Best Regards,
Thanks for the assistance Jin-Yu Yin, but that is what I do now and I want to improve it...
I want to use the
p.StandardOutput.BaseStream.BeginRead() asynchronous read method, to display results when the command console gets them, so as to incrementally build the output.
Meaning, that whenever the console outputs a line, this line gets displayed on the webform, so I don't have to wait untill the commands are finished before I can start displaying results...
Any thoughts?
Thanks
Well,
I'm afraid you cann't do this, AJAX is not a server push tech.
When a Async-postback is finished, the Textbox1.text change.How can you fired a postback whenever the console outputs a line?
You cann't "push" the result to the client-side when the console outputs a line!
Best Regards,
No comments:
Post a Comment