简体   繁体   English

在任务调度程序中使用 java 程序执行 bat 失败

[英]execute bat with java program in task scheduler fail

I have the following script that works fine if executed manually but it does not work if set as a task in the task scheduler, I suspected that is a parameter that is not set right but I can spot it hopefully someone can help me to resolve this riddle我有以下脚本,如果手动执行,它可以正常工作,但如果在任务调度程序中设置为任务,则它不起作用,我怀疑这是一个设置不正确的参数,但我可以发现它希望有人可以帮助我解决这个问题谜语

 @echo off setlocal EnableDelayedExpansion cls set AllSections= Set Action= rem set PARMS=-Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine rem set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202 rem set SIKULIX_HOME=%~dp0 set CurrentDate=%Date% set CurrentTime=%Time: =0% set CurrentTime=%CurrentTime:~0,8% set DateTimeStamp=%CurrentDate:~6,4%-%CurrentDate:~3,2%-%CurrentDate:~0,2%_%CurrentTime:~0,2%-%CurrentTime:~3,2%-%CurrentTime:~6,2% set FolderTimeStamp=%CurrentDate:~3,2%-%CurrentDate:~6,4% set DestinationFolder=SCADA\Output\%FolderTimeStamp%\%DateTimeStamp% md DestinationFolder=SCADA\Output > nul 2>&1 md DestinationFolder=SCADA\Output\%FolderTimeStamp% > nul 2>&1 md DestinationFolder=SCADA\Output\%FolderTimeStamp%\%DateTimeStamp% > nul 2>&1 md DestinationFolder=SCADA\Output\%FolderTimeStamp%\%DateTimeStamp%\Settings > nul 2>&1 md DestinationFolder=SCADA\Output\%FolderTimeStamp%\%DateTimeStamp%\Alarms > nul 2>&1 md DestinationFolder=SCADA\Output\%FolderTimeStamp%\%DateTimeStamp%\Network > nul 2>&1 rem Create Settings file rem echo "Hello world" > %cd%\aa.txt rem \\\--below instructions working as script from command prompt, but not from task scheduler C:\sikulix\sikulixapi-2.0.5-win.jar -r C:\sikulix\Scada\Settings.sikuli C:\sikulix\sikulixapi-2.0.5-win.jar -r C:\sikulix\Scada\Alarms.sikuli C:\sikulix\sikulixapi-2.0.5-win.jar -r C:\sikulix\Scada\Networks.sikuli rem ///// ENDLOCAL:End

I highlighted the bit that does not work the folder are been set correctly but the java part fail to be executed in the task scheduler but as I said is fine manually.我强调了不起作用的位,文件夹设置正确,但 java 部分无法在任务调度程序中执行,但正如我所说的手动操作很好。 thanks for your time谢谢你的时间

The launcher you use depends on Windows having the file extension .jar mapped to a particular JVM.您使用的启动器取决于 Windows,其文件扩展名为.jar映射到特定的 JVM。 On my PC a .jar file double click or typing some.jar someparams would just open the jar with 7Zip rather that launch a Java app. On my PC a .jar file double click or typing some.jar someparams would just open the jar with 7Zip rather that launch a Java app.

Re-write the script to use a valid Java runtime such as %JAVA_HOME%/bin/java , or check that the task scheduler account maps .jar handling to a suitable JVM.重新编写脚本以使用有效的 Java 运行时,例如%JAVA_HOME%/bin/java ,或检查任务调度程序帐户是否将.jar处理映射到合适的 Z18B5A217C4DAD2566EDZE3A059

In Windows Explorer, you can check the mappings with right mouse -> Properties then see "Open with:" field.在 Windows Explorer 中,您可以使用鼠标右键检查映射 -> 属性,然后查看“打开方式:”字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM