2.0 read console output


Is there away in 2.0 to read a console output live?
1) Startup console script/app
(I think this code will do the job but most likely there is something beater

Open in new window

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

Thank you
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.

You can do it using batch file, here is link with sample code file as well.
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  
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.
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 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.
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" "">
<html xmlns="">
<head runat="server">
    <title>Demonstrate piping input to and output from external program</title>
    <form id="form1" runat="server">
        <asp:Label ID="lblResults" runat="server" Text=""></asp:Label>

<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

        Return proc.StandardOutput.ReadToEnd

    End Function

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.