Ok, the last one was too easy, so here's a deep one.
I'm writing a script for backing up files daily on my computer, which is running Win2000. The "backup" consists in copying a specified list of files to a separate directory (for subsequent manual transfer to a CD).
(I know there are existing backup utilities, but I don't know of one that provides the flexibility I need, and can obtain through writing my own script.)
1) My first attempt uses the Windows task scheduler to run a Perl script (via a .bat file) every two hours. The script uses a file to keep track of when the last backup was completed. Each time the script runs, it checks to see whether a backup was done within the last 24 hours. If so, the script simply exits. Otherwise it tells me it's time to do a backup, and asks me whether to proceed. If I say "yes", it does the backup and then reports that it's done, or displays any errors that occurred. If I say "no" (because I'm in the middle of doing something else with which the backup might interfere), the script exits.
This works fine, except for
one annoying problem: Each time the script runs (every two hours), a command prompt window flashes up, even if the script doesn't produce output or request input.
Someone suggested setting up the scheduled task to run as a user other than the one who's logged on. That supposedly would prevent the command prompt window from appearing. I haven't actually tried this, but I suspect that the window would not be present even if the script needed to produce output or request input, so that wouldn't work.
2) My second approach was to write a Windows service, instead of using the task scheduler.
I found a cool Perl module
Win32::Daemon that makes it relatively easy to write a service.
The first problem I ran into is
how to interact with the service, since it needs to tell me when it's time to do a backup, and ask me for permission to proceed. I couldn't figuring out any way of getting a command prompt window to appear. Script input/output just seems to disappear into the bit bucket (that includes Perl compilation errors as well, but that's getting off track).
I'm currently attempting to use the Perl Tk module, included with the Perl distribution I have, to interact with the user. This sort of works, but it opens another can of worms, since now I have to deal with the Tk event loop, and probably using a secondary thread to do the backup itself, which can take several minutes, all inside a service.
Does anyone have any experience with this kind of stuff that might help?
