有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从USB驱动器在jar文件中执行运行时命令?

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

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

我把它打包成一个Jar文件,它在C:/drive上运行良好。 但我把它复制到USB钥匙链驱动器后,它就不会运行了

还有我的汉英词典。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:/or F执行:/

显而易见的是:当从C:/运行时,它是:C:\Dir\u PC\u Customizer>;cscript

从F:/运行时,它是F:\Dir\u PC\u Customizer\dist>;cscript

错误消息显示:“F:\Dir\u PC\u Customizer\dist\PinItem.wsf”未找到,因为PinItem。wsf和其他几个文件位于:F:\Dir_PC_Customizer[和C:\A_Test\Dir_PC_Customizer]中,不在dist中

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

我想一种方法是告诉它“虽然我在“F:\Dir\u PC\u Customizer\dist”中运行,但假装我在“C:\A\u Test\Dir\u PC\u Customizer”中运行”,但如何告诉它切换目录?这是关键


共 (0) 个答案