Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Screen Output of Messages

by /dev/trash (Curate)
on Dec 13, 2003 at 04:12 UTC ( #314472=perlquestion: print w/replies, xml ) Need Help??
/dev/trash has asked for the wisdom of the Perl Monks concerning the following question:

I have this snippit of code:
#!/usr/bin/perl use warnings; use strict; use English; use diagnostics; use File::Copy; use File::DosGlob qw(glob); my $error=0; copy($_,'Z:/mail_test') foreach glob 'E:/EudoraPro/*.mbx'; printf ("Mailboxes done!\n"); copy($_,'Z:/mail_test') foreach glob 'E:/EudoraPro/*.toc'; printf ("TOC's done!\n");
Some of it I picked up elsewhere some of it is my own. What I wanted it to do was to copy all the *.mbx and *.toc files to a network share for backup purposes and then to tell me it completed that task. The copying works fine, but I never see the "Mailboxes are done" and TOC's are done" messages. I'm using Activestate Perl v5.6.1 build 633 on a Windows 98 machine.

Replies are listed 'Best First'.
Re: Screen Output of Messages
by BrowserUk (Pope) on Dec 13, 2003 at 06:34 UTC

    Output to stdout should be flushed to the screen when the program ends regardless of whether you are using print or printf.

    It's just a thought, but you're not by any chance invoking the script by double-clicking it in the explorer are you? And the command gets run, but the cmd window it runs in is disappearing before you get a chance to see the results?

    If so, try adding

    print 'Type any key to exit'; <stdin>;

    as the last line of the program. If that 'fixes' the problem, then you might take a look at the thread at Small Problem with running Perl Scripts in Windows for some other alternatives.

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail

      I like system('PAUSE') myself, you get all those nice dots for free :-)



      Actually I am using Java to start Eudora and when Eudora closes, I call the Perl Script from the Java program. I double click on the Java app icon to run it.
Re: Screen Output of Messages
by tachyon (Chancellor) on Dec 13, 2003 at 04:33 UTC

    Seems like a lot of work to do somthing you can do off the command line, or in perl using bactics to exec shell commands. The /Y supresses overwrite warnings COPY /? for options.

    #!/usr/bin/perl print `copy /Y E:\\EudoraPro\\*.mbx Z:\\mail_test`; print `copy /Y E:\\EudoraPro\\*.toc Z:\\mail_test`;

    Anyway it should print even though in Perl we tend to use print most of the time rather than printf with parens C style. In fact it does print for me on Win2k and AS 633. You might try adding $|++ to the top of your script to force buffer flushing but the \n should do that anyways.



      Yeah, by default perl will line-buffer output if STDOUT is a terminal, so the \n's should take care of it... unless you're sending this to a pipe or a file or some such.

      Not an editor command: Wq

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://314472]
Approved by tachyon
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-02-21 20:38 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (319 votes). Check out past polls.