提问人:PPP 提问时间:10/19/2023 最后编辑:ikegamiPPP 更新时间:10/23/2023 访问量:98
Windows 任务计划程序在尝试通过 bsub 设置时出现错误
Windows task scheduler is giving error when trying to set it via bsub
问:
当我运行命令时:
SCHTASKS /create /tn "ADW_generic" /s noivw-pulsereg3 /tr "\"U:\adw_prerun_bat_file\filesToUseInAutomatedPvReg\ADWGeneric_cic.bat\" -var 23232 " /sc ONCE /sd 12/29/2014 /st 12:00 /f
那么就没有问题来了。
但是,当我在 perl 中通过 bsub(使用 system)运行相同的命令时,如下所示:
my $cmdTriggerServerSetup = "bsub -J ADWServer -m machine1 -e //noida02/psd/error_tette.log -q win_normal \'SCHTASKS /create /tn \"ADW_generic\" /s noivw-pulsereg3 /tr \"\"U:\\adw_prerun_bat_file\\filesToUseInAutomatedPvReg\\ADWGeneric_cic.bat\" -var 23232 \" /sc ONCE /sd 12/29/2014 /st 12:00 /f\'";
出现以下错误:
ERROR: Invalid argument/option - '-var'.
Type "SCHTASKS /CREATE /?" for usage.
我怎样才能摆脱这个错误?我知道错误在某种程度上是由于引号引起的,因此需要帮助弄清楚如何将引号添加到命令中。
我希望所需的字符串是SCHTASKS /create /tn "ADW_generic" /s noivw-pulsereg3 /tr "\"U:\adw_prerun_bat_file\filesToUseInAutomatedPvReg\ADWGeneric_cic.bat\" -var 23232 " /sc ONCE /sd 12/29/2014 /st 12:00 /f
但是当我用作:
my $cmdTriggerServerSetup = "bsub -J ADWServer -m machine1 -e //noida02/psd/error_tette.log -q win_normal \'SCHTASKS /create /tn \"ADW_generic\" /s noivw-pulsereg3 /tr \"\\"U:\\adw_prerun_bat_file\\filesToUseInAutomatedPvReg\\ADWGeneric_cic.bat\\" -var 23232 \" /sc ONCE /sd 12/29/2014 /st 12:00 /f\'";
它给了我一个错误,因为:
Bareword found where operator expected at test.pl line 24, near "U"
(Missing operator before U?)
我遵循了池上以下答案中提出的问题:
my $var1="23232";
my $testScriptBuilder2=sub {
my $relName=$_[0];
return "SCHTASKS /create /tn \"ADW_generic\" /s noivw-pulsereg3 /tr \"\\"U:\\adw_prerun_bat_file\\filesToUseInAutomatedPvReg\\ADWGeneric_cic.bat\\" -var $var1\" /sc ONCE /sd 12/29/2014 /st 12:00 /f";
};
my $testCommand=$testScriptBuilder->($relName);
system(
bsub => (
-J => "ADWServer",
-m => "spb2k864svr2",
-e => "//noinapb02/psdstore4/pvts_CM/bin.wint/LSF_work/logs/machine_health_check/22.1_ISR/error_tette.log",
-q => "win_normal",
$testCommand,
)
);
运行此脚本时,我收到错误:
ERROR: Invalid argument/option - '-var'.
Type "SCHTASKS /CREATE /?" for usage.
但是,当我在 shell 命令行上运行它时,它运行良好。由上述命令生成器生成的命令是:
SCHTASKS /create /tn "ADW_generic" /s noivw-pulsereg3 /tr "\"U:\adw_prerun_bat_file\filesToUseInAutomatedPvReg\ADWGeneric_cic.bat\" -var 23232" /sc ONCE /sd 12/29/2014 /st 12:00 /f
答:
我们想构建一些命令。为了构建它们,我们将需要这个:
use String::ShellQuote qw( );
use Win32::ShellQuote qw( ); # Can be installed and used on any platform.
# Import with custom names.
BEGIN { *quote_for_sh = \&String::ShellQuote::shell_quote; }
BEGIN { *quote_for_win32 = \&Win32::ShellQuote::quote_native; }
首先,我们需要构建一个 Windows 命令。
my $task = quote_for_win32(
'U:\\adw_prerun_bat_file\\filesToUseInAutomatedPvReg\\ADWGeneric_cic.bat' => (
-var => $var1,
)
);
然后是另一个。
my $remote_cmd = quote_for_win32(
schtasks => (
"/create",
"/tn" => "ADW_generic",
"/s" => "noivw-pulsereg3",
"/tr" => $task,
"/sc" => "ONCE",
"/sd" => "12/29/2014",
"/st" => "12:00",
"/f",
)
);
我们可以构建一个 sh 命令来传递到这里。system
my $local_cmd = quote_for_sh(
bsub => (
-J => "ADWServer",
-m => "machine1",
-e => "//noida02/psd/error_tette.log",
-q => "win_normal",
$remote_cmd,
)
);
但是我们可以直接启动,而不是使用 shell 中介。bsub
system(
bsub => (
-J => "ADWServer",
-m => "machine1",
-e => "//noida02/psd/error_tette.log",
-q => "win_normal",
$remote_cmd,
)
);
如果需要捕获输出或其他内容,请使用 IPC::Run 而不是 .run
system
评论
ERROR: Invalid argument/option - '-var'. Type "SCHTASKS /CREATE /?" for usage.
my $remote_cmd = 'SCHTASKS /create /tn \"ADW_generic\" /s noivw-pulsereg3 /tr \"\"U:\\adw_prerun_bat_file\\filesToUseInAutomatedPvReg\\ADWGeneric_cic.bat\" -var 23232\" /sc ONCE /sd 12/29/2014 /st 12:00 /f';
工作。但是,如果我想将 -var $var 1 设置为 (my $remote_cmd = 'SCHTASKS /create /tn \"ADW_generic\" /s noivw-pulsereg3 /tr \"\"U:\\adw_prerun_bat_file\\filesToUseInAutomatedPvReg\\ADWGeneric_cic.bat\" -var \'$var1\'\" /sc ONCE /sd 12/29/2014 /st 12:00 /f';
)
评论
qq
q
SCHTASKS /create /tn "ADW_generic" /s noivw-pulsereg3 /tr "\"U:\adw_prerun_bat_file\filesToUseInAutomatedPvReg\ADWGeneric_cic.bat\" -var 23232 " /sc ONCE /sd 12/29/2014 /st 12:00 /f