我有一个必须运行数千次的命令,即
command.exe -X="AAA"
command.exe -X="AAB"
...
command.exe -X="ZZZ"
它将来自AAA-> ZZZ
每个命令都将返回“成功”或“失败”。制作一个以
格式运行所有这些命令的程序的最有效方法是什么AAA: Success
AAB: Failure
...
我的第一个想法是生成每个大写alpha可能性的列表,然后将其与命令连接并将其粘贴到批处理文件中,但必须有一种更简单的方法来运行它。
答案 0 :(得分:4)
for my $i ('AAA'..'ZZZ') {
print qq{command.exe -X="$i"}
}
答案 1 :(得分:4)
几乎与Miller's answer完全相同,只是这实际上会运行命令并打印相应的输出:
for my $i ('AAA'..'ZZZ') {
my $output = `command.exe -X="$i"`;
print "$i: $output\n";
}
答案 2 :(得分:3)
对于纯批次选项
@echo off
setlocal enableextensions enabledelayedexpansion
set "r=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for /l %%n in (0 1 17575) do (
set /a "a=%%n/676", "b=(%%n %% 676)/26", "c=%%n %% 26"
for %%a in (!a!) do for %%b in (!b!) do for %%c in (!c!) do (
set "X=!r:~%%a,1!!r:~%%b,1!!r:~%%c,1!"
for /f %%x in ('command.exe -X="!X!"') do echo(!X!:%%x
)
)
答案 3 :(得分:2)
我如何修改它从000到ZZZ?
你会从cpan
中找到Number::AnyBase
sub iter {
my ($len, $start) = @_;
$len ||= 3;
$start ||= 0;
use Number::AnyBase;
my $c = Number::AnyBase->new([ 0..9, 'A'..'Z' ]);
my $end = $c->to_dec("Z" x $len);
return sub {
return if $start>$end;
my $s = sprintf("%${len}s", $c->to_base( $start++ ));
$s =~ s/ /0/g;
return $s;
};
}
my $it = iter();
while (my $i = $it->()) {
my $output = `command.exe -X="$i"`;
print "$i: $output\n";
}
答案 4 :(得分:0)
另一种纯批次解决方案:
@echo off
setlocal EnableDelayedExpansion
for /l %%a in (65,1,90) do for /l %%b in (65,1,90) do for /l %%c in (65,1,90) do call:# %%a %%b %%c
exit/b
:#
set $#=
for %%* in (%1 %2 %3) do (cmd /c exit %%*
set $#=!$#!!=exitcodeascii!)
echo Treating : !$#!
for /f "delims=" %%z in ('command.exe -X="!$#!"') do echo !$#! : %%z