I would like to be able to detach my program from the console much like wget -b. A code fragment might look like
static void Main(string[] args)
{
var settings = new Settings(args);
if (settings.Background)
{
/*Tell the user what's going on.*/
System.Console.WriteLine("Detatching from console. The program will still be running.");
System.Console.Out.Close();
}
/*do work then exit.*/
}
But System.Console.Out.Close(); doesn’t do the right thing.
To clarify, the “right thing” is, when running this program from the console, the prompt should re-appear. Or, when running this program from explorer.exe, the console window should close.
Please let me know if I am not being clear.
The source for
wgetto which you refer is available here. You’ll notice that in mswindows.c lines 193 – 314, a fork procedure is implemented. They spawn a new instance ofwgetand pass it the same parameters.The comments are informative, too:
And on line 102:
The short answer seems to be “Don’t do that.”