in reply to forcibly exiting script

I was just mucking around with Win32::Console. You can also use this to fork a detached process just fine. Here is a little alarm clock daemon example. When it runs it pops a console and asks for a sleep time. It then detaches from the console which closes. Next it forks. The parent just exits whilst the child sleeps for x seconds, pops a new console window and prints a message (just to prove it is alive and kicking). This new console disappears when the child exits 5 seconds later.

#!/usr/bin/perl -w use strict; use Win32::Console; my $con = Win32::Console->new(); $con->Display; $con->Write("Sleep how many seconds? "); chomp(my $sleep = <STDIN>); $con->Free(); # detatch our script from the console which closes # now let's fork of an alarm clock child defined ( my $pid = fork() ) or die "Can't fork $!\n"; if ($pid) { exit; } else { sleep $sleep; $con->Alloc() or die $!; $con->Write("BZZT - this is your wake up call"); sleep 5; exit; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: forcibly exiting script
by Anonymous Monk on Aug 14, 2001 at 18:45 UTC
    However, in my case, I want the script to send output to the console, read some input, fork a process, send more output to the (same) console, fork another process, send more output, fork another process, send more output, then quit. As I understand $con->Free(), I think it permanently detaches from the console. Sorry for being unclear.

    Thanks,

    Glenn

      OK, using the Win32::Process with DETACHED_PROCESS when starting the app seems to have cleared up my problem. Honestly, my code in total looks like garbage, but it runs. Thank you Perl ;)

      Later,

      Glenn