prad_intel has asked for the wisdom of the Perl Monks concerning the following question:

Hi All

I usually play a movie in my PC before I sleep and as everyone i dont know when I sleep and till next day morning the movie keeps on looping.

I usually get scoldings for keeping the PC ON the whole night.

I decided to avoid scoldings and recently wrote a too small PERL script which would shutdown when i sleep ( although i know i can do it without PERL too using shutdown.exe - t XX but i want to run everything on PERL hereafter). The code goes something like this ...
sleep 1800; # am sure to sleep in half an hour system "c:\\windows\\system32\\shutdown.exe -s";
But I did find that the shutdown occurs without closing applications and during the next start Windows checks for errors quoting improper shutdown.

Actually I want to do something like -

1) Close the Windows Media Player which is running the video.

2)Then shutdown

I consulted me friend and he is telling that to close windows media player i need to track process id or pid , Is that necessary ?

Also how do i close other folders using perl and make a safe shutdown.

Regards

prad

2005-09-27 Retitled by g0n, as per Monastery guidelines
Original title: 'perl help while sleeping !'

Replies are listed 'Best First'.
Re: Using Perl to shutdown windows
by GrandFather (Saint) on Sep 26, 2005 at 10:30 UTC

    This can be hard to do because before the system will shut down it has to be able to close all open applications. Generally that can fail if there are unsaved documents and such. From Perl on Windows you can use Win32::InitiateSystemShutdown from the Win32 module to initiate the shut down.


    Perl is Huffman encoded by design.
Re: Using Perl to shutdown windows
by puploki (Hermit) on Sep 26, 2005 at 10:35 UTC

    As GrandFather has said, there are some native Perl ways of doing this, however, it may be just as easy to use the -f option with shutdown which forces any open applications to close.

    This is a "safe" shutdown from the point of view of Windows, i.e. it will stop the OS cleanly so it shouldn't winge on the way back up. You will lose any unsaved data in applications though.

    From your description of Windows checks for errors on starting again, it sounds as though you're using Windows 95/98/ME (but I could be wrong) - switch over to XP Pro and NTFS and you shouldn't have these problems :)

Why shutdown?
by schwern (Scribe) on Sep 27, 2005 at 00:23 UTC

    Why not just let the computer go to sleep? If you turn off the movie looping it should go into power save mode and effectively be "off" for the purposes of consuming electricity.

    If you really want to shut down, maybe Win32::Shutdown will help? Win32::Process (part of libwin32) might help with identifying and closing your Windows Media Player process.