in reply to How to execute dos commands from Perl

In a WindowsXP/cygwin environment, I was able to get this to work:

perl -e "print for qx|c:/windows/system32/cmd.exe /c test.bat| "

Note the use of the full path to cmd.exe, using FORWARD SLASHES.

             I hope life isn't a big joke, because I don't get it.
                   -SNL

Replies are listed 'Best First'.
Re^2: How to execute dos commands from Perl
by Poornima (Initiate) on May 31, 2012 at 06:35 UTC
    Hi, Thanks for your quick response. But i need to call up a .exe from within a perl script and after execution the command should return to next step in perl script. Can you please help me out on it?
      Yes - the 'qx' and backticks provide that functionality. The perl script waits for the command to complete, then executes the next perl command.
      use strict; use warnings; my $externalExe="C:/path/to/myprog.exe"; print "Starting external program...\n"; print for qx|$externalExe 2>&1|; # Executes the program, and prints it +'s output print "Program $externalExe run completed.\n";

                   I hope life isn't a big joke, because I don't get it.
                         -SNL

      If you want to execute a .bat under Windows, then you need to have a script file that Windows understands.

      I suggest that you type: "help start"
      to see the options for that to make a more complex Windows .bat file.

      To capture the output of a shell command (Windows or not) in Perl in the most simple way, use "backticks".

      #!/usr/bin/perl -w use strict; my $result1 = `dir`; print $result1; my $result2 = `dir *.txt`; print $result2;