【问题标题】:Incorrect format or out of bounds error while setting up schedule task设置计划任务时格式不正确或超出范围错误
【发布时间】:2019-03-05 10:09:35
【问题描述】:

我正在尝试在 PHP 中创建计划任务,但出现错误。

$input = 'schtasks /create /tn testSendMail /tr "php\"D:\wamp64\www\testScheduler\SchedulerURL.php"" /sc once /st 11:00';
$input = escapeshellcmd($input);
echo $input;
$execution = exec($input." 2>&1",$output);
var_dump($execution);
var_dump($output);

当我执行这个时,我得到:

array(2) { [0]=> string(93) "Erreur�: Le code XML de la t�che contient une valeur incorrectement format�e ou hors limites." [1]=> string(12) "(39,4):Task:" }

英文:

task XML code contains incorrect values format or is out of bounds

但是当我在终端上执行这个命令行时,它会创建一个计划任务。 我搜索过,但没有发现任何关于此的内容。

【问题讨论】:

  • 你是否尝试从 php 中执行你的命令,它有效吗?
  • 直接在cmd中执行就可以了
  • 你试过$output = shell_exec($input." 2>&1");吗?
  • 我得到与 shell_exec() 完全相同的错误:(
  • 我试图用 notepad.exe 替换这个:"php\"D:\wamp64\www\testScheduler\SchedulerURL.php"" 但它也不起作用......

标签: php scheduled-tasks


【解决方案1】:

我认为问题出在你的这部分命令:

"php\"D:\wamp64\www\testScheduler\SchedulerURL.php""

转义字符时出现一些问题。

因此,我会选择:

"php \"D:\\wamp64\\www\\testScheduler\\SchedulerURL.php\""

另一个建议,尽管使用手写绝对路径,但更喜欢使用像 DIR 这样的魔法常量。

希望这会有所帮助。

【讨论】:

  • __DIR__ 可在 inside PHP 脚本中使用 - 但这是命令行。
  • 感谢您的回复!不幸的是,我尝试了您的解决方案,但它不起作用。我真的不明白这个问题。如果我尝试启动 php -i 命令而不是 schtasks 它可以工作。同样,我尝试使用notepad.exe而不是我的php脚本启动它也失败了,但它应该可以工作^^'
【解决方案2】:

好的,如果有人有同样的问题,我明白了。 这不是代码问题,问题是我在 IIS 上运行它,我已经在 wamp 上尝试过它并且它正在工作。 当我找到解决方案时,我会对此发表评论。

【讨论】:

  • 好的,我明白了!这是IIS的问题。如果您有同样的问题,只需考虑添加 /RU 和 /RP 参数
猜你喜欢
  • 2015-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-12
  • 1970-01-01
  • 1970-01-01
  • 2010-12-22
  • 2014-03-23
相关资源
最近更新 更多