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

I'm running perl in windows to generate .csv,.xls,.txt files as outputs to test scripts. The output files are sent all over the network depending on the board assembly and serial number. At the end of the scripts I find that it is cumbersome to search the network for the correct output files.

Is there a way to have windows open the specified output file at the end of the perl script using the appropriate program ie. notepad, excel?

Thanks

Replies are listed 'Best First'.
Re: open output files
by SuicideJunkie (Vicar) on Apr 27, 2012 at 18:08 UTC
    use strict; use warnings; open my $ifh, '>', 'test.txt' or die; print $ifh "Hello world\n"; close $ifh; system ('test.txt'); exit 0;
    Works for me.
Re: open output files
by ww (Archbishop) on Apr 27, 2012 at 19:40 UTC
    "perl to generate files as outputs to test scripts ...(which) are sent all over the network depending on the board assembly and serial number."

    I'm not quite clear about this: are the "test scripts" (perhaps non-Perl?) generating output that you're capturing with separate and distinct "perl" scripts and dispatching "all over the network" ... or are the test scripts written in perl (themselves) and using the board assembly and SN to determine where to send them?

    Perhaps. OTOH, that's not important. In both cases, it sounds as though you could insert into your perl script a function to tee the output -- with one copy directed to notepad [scathing sarcasm about the juxtaposition of "notepad" and "appropriate" omitted :-)] or some other, more trustworthy text editor, and the other to the existing destination-selection function.

Re: open output files
by cursion (Pilgrim) on Apr 27, 2012 at 18:09 UTC

    I don't know much about Perl on Windows, but fork and exec should work to pop open windows with those files.

    Why not make Perl move the files to where they need to be on the network?

Re: open output files
by 2teez (Vicar) on Apr 27, 2012 at 20:23 UTC

    Both system(...) and exec(...) will work, but with openning up of the output file at the end of the perl script, I will favour exec(...) over system(...), because it exceute a system command and never returns to the original process.

    check perldoc -f exec for more details

Re: open output files
by Anonymous Monk on Apr 27, 2012 at 21:08 UTC
    Hey everyone, it's me Anonymous Thanks for your comments. It works great with system() the script doesn't terminate as gracefully with exec(). I agree I wouldn't call notepad a text editor either, It's mainly for viewing not editing files. Thanks again, Matt