如何从USB驱动器中执行jar文件中的Runtime命令?

时间:2016-06-05 21:33:48

标签: java command-line runtime wsh

我的Java应用程序运行如下命令:

String Command="C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd";
Runtime.getRuntime().exec(Command);

我把它打包成一个Jar文件,它从C:/ drive运行良好。 但是在我将它复制到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],而不是在dist。

我的问题是:如果我想让它能够从任何驱动器运行:C:/,F:/或G:/,我该怎么办?

我想有一种方法可以告诉它"虽然我在" F:\ Dir_PC_Customizer \ dist"中运行,但假装我正在运行& #34; C:\ A_Test \ Dir_PC_Customizer",但如何告诉它切换目录?这是关键。

1 个答案:

答案 0 :(得分:0)

我找到答案,当应用程序运行时,将额外的几个文件从父目录复制到当前目录,以便找到它们。

相关问题