ASP.net 2.0 read console output

Hello,

Is there away in ASP.net 2.0 to read a console output live?
E.g.
1) Startup console script/app
(I think this code will do the job but most likely there is something beater
System.Diagnostics.Process.Start("cmd.exe")

Open in new window

2) Print the console output on the ASP.net page
(Not sure about the code but i know that people have got something on these lines before)

Thank you
cyberiadminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sindhuxyzCommented:
You can do it using batch file, here is link with sample code file as well.

http://www.daniweb.com/forums/thread308015.html
devlab2012Commented:
The statement System.Diagnostics.Process.Start("cmd.exe") will start cmd.exe on the SERVER not on the CLIENT.

It is not possible to capture the output from some other program unless you go in for using functions of windows sdk.
cyberiadminAuthor Commented:
I need the console app to run the ASP server and the output live to be printed on the web page (asp). Hope this help you to understand what i am trying to ask.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Ted BouskillSenior Software DeveloperCommented:
The experts have understood your question and it's not possible.  ASP.NET runs as a thread inside of the processes provided by IIS.  It is not capable of doing this.
cyberiadminAuthor Commented:
It is possible as tcadmin has done this using asp.net.  
Ted BouskillSenior Software DeveloperCommented:
Sorry I do not see that functionality.

That is a remote control panel that probably uses WMI to connect to and manage the servers remotely and likely an API that published data for consumption by their client.

You are asking for something different and it's not possible.  The command line process has not connectivity or data sharing setup to work with IIS.
HairbrushCommented:
I presume it is not actually just a command line that you want to execute - you want to call something like a batch file, or a particular command?  If so, then you can create a process and redirect the standard output to a stream, and then when the command has finished you can read the contents of the stream and set the contents of a label control to the output from the command.

Is that what you need to do?  If so, does your console application require any user input?
cyberiadminAuthor Commented:
Yes, thank you. No user input just parameters when running the console application but they are are static values that can be stored in the asp.net script. Could you please create an example?
Ted BouskillSenior Software DeveloperCommented:
This won't work with ASP.NET.  There is no console attached to the process and you cannot attach one.  In fact, for security reasons by default access to the command line is blocked in .NET.

You can lower security to run something on the command line but you cannot redirect the stdout stream used by the console.  At least I've never seen it.
HairbrushCommented:
The following VB.NET code shows how to call a console application (in this case tasklist.exe) from an ASP.NET web page and redirect the output of the console application to a label control on the web page.
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Demonstrate piping input to and output from external program</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblResults" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        lblResults.Text = MyProcess()

    End Sub

    Function MyProcess() As String

        Dim proc As New System.Diagnostics.Process()
        proc.StartInfo.RedirectStandardOutput = True
        proc.StartInfo.UseShellExecute = False
        proc.StartInfo.FileName = "C:\Windows\System32\tasklist.exe"
        Dim strArguments As String = "/FO table /FI ""MEMUSAGE gt 30000"" /NH"
        proc.StartInfo.Arguments = strArguments
        proc.Start()
        proc.WaitForExit()

        Return proc.StandardOutput.ReadToEnd

    End Function
</script>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cyberiadminAuthor Commented:
Thanks, Hairbrush.

Also, is there away of getting this to run the program on a remote server? If so, what is the code for this?

cyberiadminAuthor Commented:
Thanks for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.