Perl: Issue coming while running script via task scheduler (Windows) and not via command line

huangapple go评论56阅读模式
英文:

Perl: Issue coming while running script via task scheduler (Windows) and not via command line

问题

    my $jobs=`bjobs -w | tr -s " " | cut -d " " -f7 | tail -n +2 | sort -u | grep -i "_PV_"`;      ## 找出在cmd上运行的所有作业
    print "$jobs is jobs\n";
    my @jobsArray = split("\n", $jobs);
英文:

Below is the code which I am using (in windows(administrator mode)):

my $jobs=`bjobs -w | tr -s " " | cut -d " " -f7 | tail -n +2 | sort -u | grep -i "_PV_"`;      ## Find out all the jobs running on cmd
print "$jobs is jobs\n";
my @jobsArray = split("\n", $jobs);

When running via command line, no issue is coming .(##cygwin is installed on my system)

But, when scheduling the task via task scheduler and running, below issue is coming:

-uThe system cannot find the file specified.
tail: write error
 is jobs

How to get rid of this error?

答案1

得分: 0

Perl: Issue coming while running script via task scheduler (Windows) and not via command line

通过在任务计划程序的“启动位置”选项中添加有效路径(无权限问题),问题得以解决。

在任务计划程序的“启动位置”中没有路径时,由于脚本正在以管理员模式运行,cmd 中的默认路径将变为“C:\Windows\System32”,这可能导致一些权限问题。通过在任务计划程序的任务中添加“启动位置”路径,问题得以解决,因为它改变了在默认管理员 cmd 中打开的目录,使其成为有效的(无权限错误的)路径,例如,cd “C:\\Users”

英文:

Perl: Issue coming while running script via task scheduler (Windows) and not via command line

Problem solved by adding a valid path (with no permission issue) in "start in" option of task scheduler

With no path in "start in" of task scheduler, as script was running in administrator mode, default path in cmd would be coming "C:\Windows\System32" which might be having some permission issue. Adding "start in" path in task of task scheduler solved the problem as it changed the directory, which opens up in a default admin cmd, to a valid (permission error free) path (like, cd "C:\\Users").

huangapple
  • 本文由 发表于 2023年2月23日 19:32:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544247.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定