locked
how to keep the output prompot screen to view output instead of flashing away RRS feed

  • Question

  • How to display the output of console application to an output file and how to keep the output prompot screen to view output instead of flashing away.

    Thank you,

    Reham

    Sunday, October 8, 2006 12:23 PM

Answers

  • if you are talking about Process classes (System.Diagnostics) and running processes, you can redirect the standard input and output streams to your application. Check out this link for further information and examples:

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardinput.aspx

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx

     

    I hope the links help you in some way. If this is not what you are after, please explain in further depth what you are trying to achieve.

    Thanks

    Sunday, October 8, 2006 12:40 PM
  • If your running a console application from a command shell window - the window will remain and the output will be displayed.  

     

    So you want to capture the output into a file

    In which case you can use something like the following to capture run the bat file and capture the output as a string - which you can then use in you windows application.

        Public Function ProcessStartAndCaptureOutput(byval CmdFile as string, ByVal args As String) As String
            'Diagnostics.Process.Start(CmdFile, args)
            Dim p As Diagnostics.Process = New Diagnostics.Process
            p.StartInfo.FileName = CmdFile
            p.StartInfo.Arguments = args
            p.StartInfo.UseShellExecute = False
            p.StartInfo.RedirectStandardOutput = True
            p.Start()
            Return p.StandardOutput.ReadToEnd
            p.WaitForExit()
        End Function

    Sunday, October 8, 2006 4:49 PM
  • ok so your making a Console Application, not a WinForm app

    well this is normal since it just whizzes through everything and has no "stop". to make it "stop", you would read an input from a keyboard for example:

     

    Dim theInput as String = Console.ReadLine()

    or

    Dim theInput as ConsoleKeyInfo = Console.ReadKey()

     

    this would wait until the user presses a key and continues on to the next line of codes

    Monday, October 9, 2006 12:31 AM

All replies

  • if you are talking about Process classes (System.Diagnostics) and running processes, you can redirect the standard input and output streams to your application. Check out this link for further information and examples:

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardinput.aspx

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx

     

    I hope the links help you in some way. If this is not what you are after, please explain in further depth what you are trying to achieve.

    Thanks

    Sunday, October 8, 2006 12:40 PM
  • Additional references:

    Name  Description 
    Console.ReadKey ()  Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window. 

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=671059&SiteId=1
    ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/cpref2/html/M_System_Console_OpenStandardOutput.htm

    http://www.goldencode.com/atlos2/notes/command/command-line.html
    http://www.rs-freeware.org/adb/adbdos.htm#stdio_pipes

    Sunday, October 8, 2006 4:38 PM
  • If your running a console application from a command shell window - the window will remain and the output will be displayed.  

     

    So you want to capture the output into a file

    In which case you can use something like the following to capture run the bat file and capture the output as a string - which you can then use in you windows application.

        Public Function ProcessStartAndCaptureOutput(byval CmdFile as string, ByVal args As String) As String
            'Diagnostics.Process.Start(CmdFile, args)
            Dim p As Diagnostics.Process = New Diagnostics.Process
            p.StartInfo.FileName = CmdFile
            p.StartInfo.Arguments = args
            p.StartInfo.UseShellExecute = False
            p.StartInfo.RedirectStandardOutput = True
            p.Start()
            Return p.StandardOutput.ReadToEnd
            p.WaitForExit()
        End Function

    Sunday, October 8, 2006 4:49 PM
  • hi ahmedilyas,

        Thank you so much for your help and kind replay.

     my problem was much simpler than that .

    It was the following when i debug the program i used to press F5 not CTRL+F5 which will make the output prompet screen stay for a while to view the output but on the other hand F5 the output will just flash away so quickly.this problem i just faced when i use the console application and not windows application, but i'm sure that your reply was so helpful and  i gained new knowledge from it and i really appreciate that.

    thank you,

    Reham Osama

     

    Monday, October 9, 2006 12:27 AM
  • ok so your making a Console Application, not a WinForm app

    well this is normal since it just whizzes through everything and has no "stop". to make it "stop", you would read an input from a keyboard for example:

     

    Dim theInput as String = Console.ReadLine()

    or

    Dim theInput as ConsoleKeyInfo = Console.ReadKey()

     

    this would wait until the user presses a key and continues on to the next line of codes

    Monday, October 9, 2006 12:31 AM
  • yes i agree with you for that and i tried this idea before i got the solution to that problem. i wrote readline statement to keep the screen to view the output and i tried  to read the output from a file but i failed:(

    i know that being beginner to programming will make me face lot of problems but i believe that these problems or difficulties will make me better, i hope so.i didn't write any codes since two years ago :( and i'm trying to be on the tune again and i'n starting all over from the begining ...

    by the way i program using C# .

    I really appreciate your kind help :)thank you

    may i ask another question if you mind , i'm new to that forum and i need to know if my replies will be available for all the members or for you only i mean the one i'm replying to.

     

    Monday, October 9, 2006 12:56 AM
  • programming in C#? - you posted in the VB.NET forums.....which one are you developing with? C# or VB.NET?

    The replies are available to everyone

    Monday, October 9, 2006 8:48 AM