in reply to Re^2: Perl Background processes in Windows
in thread Perl Background processes in Windows

@ Peter Dragon, Did you ever test your script? It can never work as the script starts with a die........

A conditional die, makes all the difference in the world

$ perl -le " die 6 if 9 " 6 at -e line 1. $ perl -le " die 6 if not 9 ; die 8 " 8 at -e line 1.

Replies are listed 'Best First'.
Re^4: Perl Background processes in Windows
by gepebril69 (Scribe) on Jan 31, 2012 at 10:22 UTC
    @Peter Dragon, You are right. Maybe I posted to quickly, but no matter what $cmd I use (dir|date|xxxx.exe) it will always fail on my Windows7 x64 machine. It looks very strange to me that you can use a system call in that way. Normally you use something like `$cmd` or system() to execute a system call.

      Consider looking at perlop to see what -x does. Also, if it "always fails" (and you're interested in learning why), consider posting full code.

      Please note that dir and date are shell builtins in cmd.exe and thus never pass -x, because they are not programs that can be run. Also note that -x expects the full path to an executable and does not search $ENV{PATH}. Whether that is desired or not in the context of the above program, I don't know. Update: As the argument is passed to Win32::Process::Create(...), it makes sense to have a fully specified path, because that's what Win32::Process::Create() likely wants.

      >perl -wle "print $_, -x $_ ? ' yes':' no' for @ARGV" cmd.exe c:\WINDO +WS\system32\cmd.exe cmd.exe no c:\WINDOWS\system32\cmd.exe yes

      As to using system or backticks, these do not launch a background process. Which seems to be the purpose of the code under discussion. Actually, perlport points out system(1, ...) for launching a process in the background under Windows and OS/2.

        Proc::Background - Generic interface to Unix and Win32 background

        use Proc::Background; timeout_system($seconds, $command, $arg1); timeout_system($seconds, "$command $arg1"); my $proc1 = Proc::Background->new($command, $arg1, $arg2); my $proc2 = Proc::Background->new("$command $arg1 1>&2"); $proc1->alive; $proc1->die; $proc1->wait; my $time1 = $proc1->start_time; my $time2 = $proc1->end_time; # Add an option to kill the process with die when the variable + is # DETROYed. my $opts = {'die_upon_destroy' => 1}; my $proc3 = Proc::Background->new($opts, $command, $arg1, $arg +2); $proc3 = undef;