Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Program hanging up

by blacksmith (Hermit)
on Aug 29, 2001 at 00:39 UTC ( [id://108588]=perlquestion: print w/replies, xml ) Need Help??

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

Okay. I am having a problem with this program hanging up after it ZIP's the 3 files. I can't hit CONTROL C||A..Z to end the program. I have to totally end the command prompt application. Let me explain the background of this code. I have an array of email address and each one is to recieve a particular file. Due to the large size of the file and the small size of their mailboxes, I must ZIP the files in order for them to recieve all of their material. I believe that the program can be followed from there. I do realize that there is probably an easier way to do what I am trying to do, and I will not shun any advice. But, my main concern is what is going on with the "hanging" issue.
And just in case you are wondering why "pkzip", my supervisor wanted to use it rather than "winzip" or anything else.
Thanks.
Blacksmith
#!Perl -w use strict; use Mail::Sender; use Win32; use Win32::Process; use File::Basename; my $cmd = "C:\\Program Files\\pkzip.exe"; my $time = localtime; my $subj_line = "Price Change Worksheet for $time"; my %file = ('me@here.com'=>'P:\\TEXT\\ABC\\PCW-010.TXT','him@home.com' +=>'P:\\TEXT\\ABC\\PCW-021.TXT','her@work.com'=>'P:\\TEXT\\ABC\\PCW-02 +4.TXT'); my $work = 'me@here.com'; foreach (keys %file) { my ($name,$path,$suffix)=fileparse($file{$_},"\.[^.]*"); my $filename = "C:\\a\\$name"; sub print_error() { return Win32::FormatMessage( Win32::GetLastError() ); } my $root = $file{$_}; Win32::Process::Create(my $processobj, "$cmd", "pkzip $filename $root", 0, DETACHED_PROCESS, ".") or print_error(); my $sender = new Mail::Sender( {from => $work ,smtp => 'mail.email.com +'}) or die "$Mail::Sender::Error\n"; $sender->MailFile( {to => $_, subject => $subj_line, msg => "This is a test for \n zip files.", file => $filename}) and print "Mail sent OK." || die "$Mail::Sender::Error\n"; $sender->Close; }

Replies are listed 'Best First'.
Re: Program hanging up
by rchiav (Deacon) on Aug 29, 2001 at 05:27 UTC
    There's a couple things you can do with Win32::Process, like the "wait" method to wait for it before trying to send it. But rather than that, you should think about using Archive::Zip instead.

    Hope this helps
    Rich

Re: Program hanging up
by clintp (Curate) on Aug 29, 2001 at 04:54 UTC
    You've got two relatively complex things going on here:
    1. Creating a Zip file (Win32::P::C... and such)
    2. Sending a mail message
    I guess the basic question is, which one is failing? Done any diagnostics to get that far?

    Secondly, you're firing off another process to create this zip file and then immediately trying to send the file created. You've got two concurrent (DETACHED) processes fighting for access to this file. I'll bet you've got some sort of perverse deadlock in there.

    I think instead of W::P::C to fire off a process to create the file, just use system() or qx{}. That way you: create the file, mail it, create the next file, mail it -- no contention. I'll leave the style nits to someone else.

Re: Program hanging up
by blacksmith (Hermit) on Aug 31, 2001 at 06:33 UTC
    Sorry for the delay in my response. One of Sprint's routers went down and somehow it has affected us at work or so SWBell says. Thanks for the advice. I am looking into every idea mentioned. For now I have placed a "sleep()" function between the two main activities. Thanks again.
    Blacksmith.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://108588]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found