Re: DNScmd in perl script
by shmem (Chancellor) on Jul 28, 2008 at 21:12 UTC
|
Hey All, I have Dnscmd command in my perl script.
You have glaring errors in your script. Running it as you posted it, results in
syntax error at - line 5, near "else"
Missing right curly or square bracket at - line 6, at end of line
Execution of - aborted due to compilation errors.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] |
|
Hi Shmen ,
I forget to copy the closing bracket for the If statment
the code is
$domain = "abc.com";
@zones = `dnscmd $domain /EnumZones`;
if ($?) {
print "Error "; }
else "zones done";
| [reply] [d/l] |
|
| [reply] [d/l] |
Re: DNScmd in perl script
by pc88mxer (Vicar) on Jul 28, 2008 at 21:12 UTC
|
Technically to only test the status code you should use:
if ($? >> 8) { print "Error " }
The lower eight bits of $? contain the signal that terminated the process.
There's more info in the perldoc POSIX documentation. In particular, see the documentation for the functions WEXITSTATUS and WIFEXITED.
Note that you shouldn't always trust the status code since it is possible for the command to terminate (like via a signal) before it has a chance to set it. | [reply] [d/l] [select] |
|
| [reply] |
|
Hi ,
Yes true thing. But the value of $? m getting is -1 all the times...
| [reply] |
|
| [reply] [d/l] [select] |
|
Re: DNScmd in perl script
by toolic (Bishop) on Jul 28, 2008 at 21:14 UTC
|
Aside from the fact that the code you posted does not compile
because the if/else is missing curlies, it seems as though
the dnscmd command is failing. You should print the value of $? so that you can get more information as to the cause of the failure.
| [reply] [d/l] |
|
Hi Toolic ,
Yes I forgot to copy paste the curly brackets.
The value of $? gives me -1 . I have tried out the same command with same argument on DOS , which gives me correct zones.
if (not @zones) {
if ($?) {
print "Error "; }
else { " zones done"; }
}
So was wondering why its like that.. | [reply] [d/l] |
|
I personally believe, ajd335, that you made my day: we recommend all the time not to retype code to avoid such inconveniences, and appearently you have "selective" a copy-paste which will emulate the same error! Sorry for the humour, but please do not take it as personal attack and accept it as a good piece of advice to the effect of really using copy-paste.
| [reply] [d/l] |
Re: DNScmd in perl script
by almut (Canon) on Jul 28, 2008 at 21:21 UTC
|
In addition to what's already been said, in case $? is -1, it
means dnscmd couldn't be started (e.g. not found along PATH).
| [reply] [d/l] [select] |
|
Hi Almut,
Yes , But if I try the
C:\ > dnscmd servername /EnumZones
is giving me the correct result on Dos prompt. | [reply] [d/l] |
|
| [reply] [d/l] [select] |
|
|
|