I have a routine I've used in the past when I needed start up an external executable. This will work cross-platform on Win95, Win98, WinME, Win2k, WinXP, Linux, OSX and probably many others. The only caveat is that you must have no file named "spawn.pl" in the directory your script resides in. You will probably need to adjust the calling parameters for different OS's (It is unlikely that Linux or OSX will have an executable called "NotePad"), but in general this is pretty cross platform.

It is essentially just a fork and exec, without explicitly doing one. Useful, because it is extremely difficult to fork a program running under Perl/Tk, (under Windows, at least), This neatly sidesteps the problem.

use strict; use warnings; use Tk; my $top = MainWindow->new; $top->geometry('100x100'); $top->Button( -text => 'Open A File', -command => sub{ my $types = [ ['Text Files', [qw/.txt .text .bat/]], ['All Files', ['*']], ]; my $filename = $top->getOpenFile(-title => 'Open File' +); if (defined $filename) { spawn('Notepad.exe', $filename) } } )->pack; MainLoop; sub spawn{ # Routine to spawn another perl process and use it to ex +ecute an external program my $args = join ' ', @_; unless (-e 'spawn.pl'){ open my $spawn, '>', 'spawn.pl'; print $spawn 'exec @ARGV;'; } if ($^O =~ /Win/) { $args = '"'.$args.'"'; }else{ $args .= ' &'; } system "perl spawn.pl $args"; }

In reply to Re^3: how to open a separate notepad by thundergnat
in thread how to open a separate notepad by arunmep

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.