index > Visual C# General > command prompt return immediately when running console applicatio...

command prompt return immediately when running console applicatio...

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.




programmer
sean_n

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.

daniel testa
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?


programmer
sean_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.




** Microsoft Community Moderator ** http://born2code.net **
PJ. van de Sande

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.

daniel testa
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 )





** Microsoft Community Moderator ** http://born2code.net **
PJ. van de Sande

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.

daniel testa
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() );
}





** Microsoft Community Moderator ** http://born2code.net **
PJ. van de Sande
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.


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



** Microsoft Community Moderator ** http://born2code.net **
PJ. van de Sande

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?




programmer
sean_n
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?



** Microsoft Community Moderator ** http://born2code.net **
PJ. van de Sande
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.



** Microsoft Community Moderator ** http://born2code.net **
PJ. van de Sande
reply 13

You can use google to search for other answers

 

More Articles

• How to batch download client directorys to win app then batch upl...
• Is it ok to reuse the designer in my app?
• What is My.Resources equivalent in C# ?
• MSMQ (Messaging Queue)
• Issues pulling data from a secured site using the HttpWeb systems...
• Is it possible to write data to Excel file as I like?
• Writing directly to the console buffer
• Threads newbie
• what is ADO.net??
• Best C# book
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Open a MSAccess Report that uses a param
• AxSHDocVw
• Factory pattern, possible in C#?
• Combobox inside datagridview
• Cannot make a debug release anymore
• DllImport call using a struct as param t
• How do you define a method with optional
• Getting an image out of the resources
• Is it generally more efficient to pass b
• PDF "save as" from asp.net
• DirectX Redistribute Error
• Selecting a pixel region ?
• When to use Interface?
• How to find a System Tray Process
• Using SqlConnection.Open repeatedly

Hot Articles

• I can't use mshtml library in Visual C#
• Help--Setup and Deployment with custom UI
• How can I disable selecting text from my
• window service unable to launch process
• Do I need to implement Dispose() if my C
• Request[] html
• quection about how to secure application
• How do I select Images from my External
• Windows Service ?
• Disable certain keys
• My question is so basic I'm ashamed to a
• Excel data in datagridview
• using keyword or calling dispose with co
• Getting information about file extension
• ADO.net

Recommend Articles

• Rounding a number to a number divisable
• Reg the usage of appconfig
• Raising Custom exception over MultiThreads
• c++ interop with c#
• References issue
• Accessing Outlook items in C#
• Effect on Hashtable value after compilat
• Moving a shape with mouse
• GetPixel/SetPixel very very slow...
• Whither encapsulte field in Express beta2?
• Best practice for an interruptable Worke
• Async Programming...
• Is it possible to create a mail server o
• Changing the Caption/Titlebar Font
• Assign a LinearGradientBrush to the Back