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

Hi all , I am writting a script using PL/TK which will generate a report for products. I was wondering if there is a way to invoke the notepade from the script. I mean If I click generate from my GUI then it will will just open the report with notepad without me doing it manuely . I am doing this using windows . thanks for advices.

Replies are listed 'Best First'.
Re: running notpade from perl
by NetWallah (Canon) on Mar 04, 2004 at 05:32 UTC
    Here is a safer, and more user-friendly way to accomplish what you want, based on the file EXTENSION:
    my $generatedfile = "outfile.txt"; system $generatedfile ;
    Notice the absence of any reference to NOTEPAD.

    This makes the program independent of the Name or location of Notepad. It makes the program more friendly, because it invokes the DEFAULT text editor, which may be different from notepad (Mine is ConText, not notepad).

    Yes, it adds a dependency on the file type, but that is under your control, and I think the friendliness and resiliancy of this method make it superior.

    "Experience is a wonderful thing. It enables you to recognize a mistake when you make it again."
Re: running notpade from perl
by Roger (Parson) on Mar 04, 2004 at 04:07 UTC
    Many ways to do it.

    The simplest (I think):
    # ... generate your report to report.txt ... system ("C:\\Windows\\notepad.exe report.txt");

Re: running notepad.exe from perl
by arden (Curate) on Mar 04, 2004 at 04:13 UTC
    after you've closed the output file, do this:
      system('notepad',$absolute_path_to_report);

    As long as you haven't altered your %PATH% variable, notepad.exe is in your path. The downside to putting an absolute pathname for notepad is that your script won't work if the user is using a different flavor of Windows or if they've installed to somewhere non-default for whichever flavor you originally code for.

    - - arden.

Re: running notpade from perl
by crabbdean (Pilgrim) on Mar 04, 2004 at 10:11 UTC
    Some good answers to your questions already, so I'll ask some additional stuff. For what reason are you wanting to open it to Notepad? To copy it, to view it? If you are in TK then you may want to consider the TK:Text or even the TK::Text::Supertext modules. They offer you a whole swag of possibilities that are available in notepad, but don't make it dependent on an external application.

    Also if you want it in clipboard to copy somewhere else after running you could use the Tk::clipboard module.

    Hope that helps.

    Dean

    Programming these days takes more than a lone avenger with a compiler. - sam
Re: running notpade from perl
by halley (Prior) on Mar 04, 2004 at 14:26 UTC
    If you just type system("notepad $filename"), then the Tk main loop will be held up until the user closes Notepad. This means that the Tk window won't get painted. (At least in all the versions of Tk I've used.) Kinda ugly.

    If you want to spawn Notepad but don't want to pause the script waiting for Notepad to close, use Windows' START command:

    system("start /b notepad $filename");
    This runs Notepad in the "background" (a misnomer, since it will be activated just fine for the user to see it), and the script will continue immediately.

    The Unix tradition is to allow the default editor to be configured, such as with an environment variable. The user can adjust this before running your application, if desired. I would code this like this:

    my $editor = $ENV{EDITOR} || 'notepad.exe'; system("start /b $editor $filename;

    --
    [ e d @ h a l l e y . c c ]