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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: run exe
by Corion (Patriarch) on Jul 19, 2007 at 07:15 UTC

    Running external programs can be done in many ways, depending on what you actually want. system is one way. It allows you to run a program and tells you about the exit status.

    If you want to capture the output of a program, see the backticks or qx() operator in perlop.

    If you need to provide input to the program, you can open it via the open() command as follows:

    open PAGER, "| more"; for (1..1_000) { print {PAGER} "Line $_\n"; };

    If you need to both, read and write, there are IPC::Open2 and IPC::Open3.

    All of these options are discussed in more detail in perlipc.

Re: run exe
by cdarke (Prior) on Jul 19, 2007 at 08:30 UTC
    "is anyther option to run the exe's in perl."

    Yes - you can use the OS specific APIs. Generally these are only needed if you want greater control, for example running asynchronously (in the 'background'). For Windows you can use Win32::Process::Create, but it is not as simple as system.
    One of the things which surprises Windows users when running scripts is that 'file association' is not done by the OS but by the application. Hence:
    system('myscript.pl');
    does not work. However,
    system('perl myscript.pl');
    does work - if you have %path% setup. If you are using Win32::Process::Create you need the full path name, and to set that from a file extension you can use Win32::FetchCommand.

      That's not entirely true:

      Q:\>dir tmp.pl Datenträger in Laufwerk Q: ist homes_xxx$ Volumeseriennummer: DEAD-BEEF Verzeichnis von Q:\ 19.07.2007 10:16 188 tmp.pl 1 Datei(en) 188 Bytes 0 Verzeichnis(se), 73.669.185.536 Bytes frei Q:\>type tmp.pl my $line_length = 10; my $line = '123 1234 12345 123456 1234567'; my @lines = ($line =~ /(.{1,$line_length}(?:\s|$))/g); print "-" x $line_length,"\n"; print "$_\n" for @lines; Q:\>perl -e "system('tmp.pl')" ---------- 123 1234 12345 123456 1234567

      Windows also has magic to run files based on their execution and no special Perl voodoo is needed, but you need to set up the file associations correctly:

      Q:\>ftype Perl Perl="C:\Programme\perl\bin\perl.exe" "%1" %* Q:\>assoc .pl .pl=Perl

      And, mildly surprising, the help text for ftype even mentions Perl.

        I think that works because cmd.exe is doing the association. If you use Win32::Process::Create then no automatic association is done.
      hai cdarke,

      Thanks for ur reply ill be keep in touch.

      Regards,

      RSP
Re: run exe
by GrandFather (Saint) on Jul 19, 2007 at 07:17 UTC