【发布时间】:2016-06-05 21:33:47
【问题描述】:
我的 Java 应用运行如下命令:
String Command="C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd";
Runtime.getRuntime().exec(Command);
我将它打包成一个 Jar 文件,它在 C:/ 驱动器上运行良好。 但是我把它复制到USB钥匙串驱动器后,它就无法运行了。
而我的 Chinese_English_Dictionary_PinItem.cmd 文件是:
@echo off
set ITEM=
set TASKBAR=
set ITEM=/item:"C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe"
set TASKBAR=/taskbar
echo on
:: Pin to Taskbar
cscript //nologo PinItem.wsf %ITEM% %TASKBAR%
当它从 C:/ 运行时,输出如下所示:
Command = C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd
Result :
Executing : C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd
C:\Dir_PC_Customizer>cscript //nologo PinItem.wsf /item:"C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe" /taskbar
Property item is now = C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe
Property taskbar is now =
Microsoft Deployment Toolkit version: 6.1.2373.0
------------ Initialization PinItem -------------
The /item switch specified with value: C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe
The /taskbar switch was specified.
Function-GetSpecialFolder: Cannot determine special folder for CSIDL_PROFILES
Item "C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe" pinned successfully
------------ Departing PinItem -------------
PinItem processing completed successfully.
但是当它从 USB 驱动器运行时,输出如下所示:
Executing : C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd
F:\Dir_PC_Customizer\dist>cscript //nologo PinItem.wsf /item:"C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe" /taskbar
Input Error: Can not find script file "F:\Dir_PC_Customizer\dist\PinItem.wsf".
注意:它们执行的是同一个文件:
C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd
它们只是从 C:/ 或 F:/ 执行
显而易见的是:从 C:/ 运行时,它是:C:\Dir_PC_Customizer>cscript
当从 F:/ 运行时,它是 F:\Dir_PC_Customizer\dist>cscript
并且错误消息显示:“F:\Dir_PC_Customizer\dist\PinItem.wsf”未找到,因为 PinItem.wsf 和其他几个文件位于:F:\Dir_PC_Customizer [和 C:\A_Test\Dir_PC_Customizer] 中,不在区域内。
我的问题是:如果我想让它能够从任何驱动器运行:C:/、F:/ 或 G:/,我该怎么办?
我想一种方法是告诉它“虽然我在“F:\Dir_PC_Customizer\dist”中运行,但假装我正在从“C:\A_Test\Dir_PC_Customizer”运行,但如何判断切换目录?这才是关键。
【问题讨论】:
-
Chinese_English_Dictionary_PinItem.cmd 是否与您的 jar 分布在同一文件夹中?
-
它不在罐子里。
标签: java command-line runtime wsh