On Dec 7, 4:29 am, perl...@gmail.com (Perl Pra) wrote:
> Hi All,
>
> I need to execute "*psexec.exe"* which is in C:\Windows\system32 through
> perl scirpt.
> .I am getting  the error "*'psexec' is not recognized as an internal or
> external command,operable program or batch file"*
>
> Below is the perl script.
>
> --- SNIP
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> use File::Copy;
> use File::Find;
>
>  $ENV{path}= $ENV{path} . ';' .  'C:\\Windows\\System32';
> my  $cmd='psexec' . " " . '\\\\' . 10.1.1.121 . ' -u ' .  "Adminuser"  . '
> -p ' . "adminpassword" . ' -w ' .  "C:\\commands\\AutoIT\\ ".  "
> \"C:\\commands\\AutoIT\\sch.bat\"";
> system("$cmd") or die "$!";


Did you already try printing out $cmd before calling 'system" to
see what actually gets passed ...?

Also, in case of error, the error value will be found in  $?
normally.
Only if the return is -1 can $! be inspected for the error.  See
perldoc -f system.

And your expression reports an error only if the system return
is zero.  That's backwards  since a successful call exits with 0.
At least normally...

Here's what the doc (perldoc -f system) recommends:

system ($cmd );
if ($? == -1) {
      print "failed to execute: $!\n";
}
elsif ($? & 127) {
    printf "child died with signal %d, %s coredump\n",
        ($? & 127),  ($? & 128) ? 'with' : 'without';
}
else {
    printf "child exited with value %d\n", $? >> 8;
}

> PS: If i directly run the command on dos promt it gets executed, I am
> getting error if I run the command through perl script only.
> Please help me with the below.
>

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to