【问题标题】:Starting batch file from Task scheduler point to C:\Windows\system32从任务计划程序启动批处理文件指向 C:\Windows\system32
【发布时间】:2020-10-14 08:40:18
【问题描述】:

我想启动一个需要打开 cmd 控制台才能工作的服务。

当我在登录后手动启动服务作者的批处理脚本时(无法关闭 - 否则服务停止工作)

@echo off
color 0
echo Preparation aplication Currenda Statistic Portal Version: 0.1 Beta (Raport) to start ...
echo Enter port, on which aplication will be available in web browser
set /p port="Enter port: "
echo Aplication will be started at: http://localhost:%port%
"libraries\bin\java.exe" -Xms2G -Xmx3G -jar raportgmin.jar --server.port=%port%

Evething 工作正常,输入的配置(与数据库的连接)保存在:

D:\Statistic Portal\data\databases

但我想自动启动此服务,所以我更改了如下脚本

@echo off
color 0
echo Preparation aplication Currenda Statistic Portal Version: 0.1 Beta (Raport) to start ...

echo Aplication will be started at: http://localhost:9090
"D:\Statistic Portal\libraries\bin\java.exe" -Xms2G -Xmx3G -jar "D:\Statistic Portal\raportgmin.jar" --server.port=9090

并从计划任务启动它 - 服务工作正常,但配置文件保存在:

C:\Windows\system32\data\databases

我的问题

为了从计划任务启动服务并将配置文件保存在

中,我需要更改什么

D:\Statistic Portal\data\databases

不在

C:\Windows\system32\data\databases

【问题讨论】:

  • 有时您需要插入cd /D 以定义当前工作目录。注意%~dp0.指的是批处理脚本的专利目录……

标签: windows batch-file cmd scheduled-tasks


【解决方案1】:

非常感谢!

我按照您的建议编辑批处理文件,一切似乎都按我的需要和需要进行。

再一次谢谢你。

@echo off
CD /D "D:\Statistic Portal"
color 0
"D:\Statistic Portal\libraries\bin\java.exe" -Xms2G -Xmx3G -jar raportgmin.jar --server.port=9090

【讨论】:

    【解决方案2】:
    您可能已经使用类似以下的想法,在一个命令中定义标题、工作目录和控制台颜色:
    @Start "Statistic Portal Version: 0.1 Beta (Raport)" /D "D:\Statistic Portal" "%__AppDir__%cmd.exe" /D /T:07 /C ""D:\Statistic Portal\libraries\bin\java.exe" -Xms2G -Xmx3G -jar raportgmin.jar --server.port=9090"
    

    显然您可以将 /C 选项更改为 /K 以在完成时保持窗口打开

    【讨论】:

      猜你喜欢
      • 2013-10-19
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-05
      • 2014-09-14
      • 2010-11-04
      相关资源
      最近更新 更多