This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / Perl programming question******************
open (HWIDS,"devid.txt") or die !;
while <HWIDS> {
system(devcon disable $_); <--------- err line
}
close(HWIDS);
******************
devcon disable is windows command for disabling hardware in system.
i got something like "can't locate object method devcon via package disable..."
doing my $result = `devcon disable $_` get what i want but i do not need any return...
someone has any idea?
-redspider(红蜘蛛);
2010-3-22
{433}
(#5961477@0)
-
try:
system("devcon disable $_");
-newstart12(pundit);
2010-3-24
(#5966300@0)
-
I did, same error...
-redspider(红蜘蛛);
2010-3-24
(#5966659@0)
-
system("/bin/ls -l /var/tmp"); works on unix. don't know why your command doesn't work
-newstart12(pundit);
2010-3-25
(#5969174@0)
-
my thoughi am not sure what i say
i think it is because after command Devcon, there is sub-command Disable, you can't find this kind of command under unix or linux, but under windows, this is quite common.
if i write system (dir c:), it will work because there is not sub-command after dir.
but i still doubt that Perl can not handle this kind of command.
-redspider(红蜘蛛);
2010-3-25
{356}
(#5970260@0)
-
path
-buma(。。。。);
2010-3-25
(#5969196@0)
-
i tried, no luck.
-redspider(红蜘蛛);
2010-3-25
(#5970246@0)
-
u sure u can run devcon disable via cmd line without referring to the full path leading to devcon thou?
-buma(。。。。);
2010-3-25
(#5970331@0)
-
yes.i already put it in system32 et put it in same directory as perl script. if not, `devcon disable $_` will not work either, right?
the error indicate it found devcon but can not interpret it in script.
-redspider(红蜘蛛);
2010-3-26
{203}
(#5971959@0)
-
I may be wrong, but you can either assign to a variable the whole command string with subcommand and argument(s), then do system($myvar); or invoke command in array mode like system("devcon", "disable", $_);
-u1a037(马鸭树);
2010-3-28
(#5975159@0)
-
i did tried the first method, got same error, i will try the array mode monday. thanks.
-redspider(红蜘蛛);
2010-3-28
(#5975502@0)
-
if hardware id contains special chars (it usually does), be sure to escape them well such as \.my modem hw id is PCI\VEN_1057&DEV_5600&SUBSYS_03001436&REV_00, I can disable/enable in perl.
F:\MyC>perl dev1.pl
PCI\VEN_1057&DEV_5600&SUBSYS_03001436&REV_00\3&61AAA01&0&70 : Enabled on reboot
Not all of 1 device(s) enabled, at least one requires reboot to complete the operation.
-u1a037(马鸭树);
2010-3-28
{290}
(#5975546@0)
-
no luck either for array mode, but i did not escape the special char in device line. i do not understand why it works with backticks but not system function.
-redspider(红蜘蛛);
2010-3-30
(#5979438@0)
-
almost certain your " is overloaded.
-u1a037(马鸭树);
2010-3-30
(#5980197@0)
-
You need double quote " for command in system().
-ready4u(就等你了);
2010-3-30
{580}
(#5978987@0)
-
thanks for advice, i will keep backticks method to get device enable or disable.
-redspider(红蜘蛛);
2010-3-30
(#5979445@0)