command prompt return immediately when running console application

By default, a console C# app will hold the command-prompt until the app exits. Is there a setting in the .NET framework that will cause the command-prompt to return immediately This is sort of analogous to running a command in the background in unix by appending & to the command.




Answer this question

command prompt return immediately when running console application

  • J A N

    sean_n wrote:
    when i run other apps from the same shell (win xp command prompt), i get the prompt back immediately. how do i make my C# app work in the same fashion

    Just return the Main method and your program will exit.



  • Frank777

    Thanks I'll try your method of creating a launcher app. But actually, it's not so much that I wanted my app to work in the background, but rather i wanted the convenience of getting the prompt back immediately so I can continue entering other commands.

    I guess I'm more used to traditional winapi development where if you created a windows application, you couldn't write output to the console and you would get the prompt back immediately. is it different with managed applications i noticed that with C# apps, you have the best of both worlds, you can display a GUI and also write to the console. is the reason why we don't get the prompt back immediately because the app can write to the console

    is there a way to get the prompt back w/o a launcher app



  • ggable

    For furter discussion, please use your other new thread: running C# windows app from the console does not return prompt immediately.

    I will close this one, so we don't gonne discusse this on multiple places.


  • Louis Frank

    You can execute an process without visability, see the code sample below. But i think you better can develop a service that will run in the background.


    ProcessStartInfo startinfo = new ProcessStartInfo( @"c:\myapp.exe" );
    startinfo.WindowStyle = ProcessWindowStyle.Hidden;
    Process.Start( startinfo )




  • dick giles

    Then you can just use my code i posted as last.


  • Jean-Paul Blanc

    it works. two things: you need to create a second app (launcher) and as far as I tried the app wasn't able to produce any console output. but if no need of console output, I agree with PJ. van de Sande about, develop a service that will run in the background.

    regards.


  • Betty01

    oh oh! sorry guys but i made a major mistake. i wrote "console application", but what i meant to write was "windows app launched from the console". i'll open another thread and phrase it correctly.

  • Donnal Walter

    Hi. The responsables of doing that are the shell and the OS not the C# language or the .Net framework. The OS because it must support Multitaksing (ms-dos does not) and the shell because it must do some system calls, ex fork (not exists in ms-dos) and exec, in order to provide that functionality.

    Regards.


  • RickKr

    can you specify those apps or give some examples what is the output of those apps what do those apps do maybe you get the prompt back immediately because those apps you are running have a short live because they do small tasks but as far as I know it is not possible to run various command-line apps at the same time from the same console as if it were unix.

    regards.


  • Jonathan Rupp

    I really don't understand your problem i geus, because it depends on the application you launche how fast it will give output and closes.

    If the process writes to the standart output stream, you can read it with the code i gave. I don't understand your problem with 'prompt back immediately', you want to continue the process on the background and start the next one or do you want to wait till the started process is finished and then start the next one


  • benjcev

    If the process has a output on the standard output stream you can read it to:


    ProcessStartInfo startinfo = new ProcessStartInfo( @"c:\myapp.exe" );
    startinfo.WindowStyle = ProcessWindowStyle.Hidden;
    startinfo.RedirectStandardOutput = true;
    Process process = Process.Start( startinfo );
    process.WaitForExit();

    using( StreamReader reader = process.StandardOutput )
    {
    Console.WriteLine( "Output of started process:\r\n" + reader.ReadToEnd() );
    }




  • Trivial

    when i run other apps from the same shell (win xp command prompt), i get the prompt back immediately. how do i make my C# app work in the same fashion

  • command prompt return immediately when running console application