Previous Thread
Next Thread
Print Thread
Rate Thread
#104913 10/10/2003 12:16 PM
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Ok, the last one was too easy, so here's a deep one. smile

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? smile

Sponsored Links
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
Admin Emeritus
Joined: Jan 2000
Posts: 5,073
If you want to create a real Win32 Service, you should look into the ActiveState Perl Development Kit. But that's a whole other thing you'd need to worry about...

Try using wperl.exe rather than perl.exe to avoid the flashing command window in the mean time.

I run a script in the background on one of my home machines to monitor a gaming server... I didn't bother trying to do anything fancy. Just minimized the window... wink

Personally, I'd avoid TK if you're just using Win32... Check out The GUI Loft , a wizardish sort of thing to put together Win32 UI elements visually.


UBB.classic: Love it or hate it, it was mine.
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
What about WxPerl ? smile

Also you can use this to hide the dosbox:

Code
use Win32::GUI;

my $DOS = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);
you can also show it again:

Code
Win32::GUI::Show($DOS);

#104916 10/11/2003 11:15 AM
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Wow, I figured this problem was so odd that I wouldn't get any responses, especially that quickly. Thanks smile

The Active State PDK, WxPerl and Win32::GUI sound interesting. I took at look at the Win32::GUI documentation, but found an article that says it wouldn't solve the flashing window problem, since the window gets displayed before the script has a chance to hide it. It looks like wperl, which I hadn't heard of before, but already exists in my distribution, is the simplest solution to my problem.

What I'll attempt is to run the two-hour task using wperl.exe instead of perl.exe, and then if the task needs to interact with me, it will "re-run itself" using perl.exe.

Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
It works perfectly. laugh

The task scheduler runs script #1 every two hours using wperl.exe. Script #1 checks to see a backup is due, and if so, it calls exec() to run script #2 using perl.exe. Script #2 interacts with me using its command prompt window and does the backup.

P.S. The reason I had to use exec() rather than system() was so that a new process would get created. At least, that's my guess, since when I tried to use system(), the second script appeared to run under the same Perl executable that the first script was running under.

Sponsored Links

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Posts: 70
Joined: January 2007
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20240430)