2015-12-21 83 views
3

我正在使用批處理文件來調用GUI。這個圖形用戶界面有一個按鈕(B1),點擊後可以調用它自己的副本。現在我想要增加GUI的優先級,無論是從批處理還是按鈕B1運行。如何使用ProcessBuilder高優先級運行java程序?

隨着批次,我能夠增加它的優先權,但不能與B1。

下面的代碼執行按鈕B1的點擊:(我使用cmd以提高優先級,我不知道是否有任何其他方式)

final ProcessBuilder processBuilder = new ProcessBuilder("cmd", 
    " /C", 
    " start /high", 
    path, 
    "-DTESTKERNEL_PROPERTIES=" + tempFile.getCanonicalPath(), 
    "-Djava.util.logging.config.file=" + loggingFile, 
    "-Djava.library.path=" + libraryPath, 
    "-cp", 
    classpath, 
    "com.abc.cde.gui.typetwo.GuiTypeTwo"); 
processBuilder.directory(new File(System.getProperty("user.dir"))); 

DTESTKERNEL_PROPERTIES是一個屬性文件,是執行代碼所需的。

這是輸出列表:

cmd, 
/C, 
start, 
/high, 
D:\jdk\jre\bin\javaw, 
-DTESTKERNEL_PROPERTIES=C:\Users\test\AppData\Local\Temp\testkernel2667928753863437728.properties, 
-Djava.util.logging.config.file=../config/logging.properties, 
-Djava.library.path=D:\TestKernalMain\lib, 
-cp, 
D:\Workspace\TestKernalMain\bin; 
D:\TestKernalMain\lib\bundled\bsh-2.0b5.jar; 
D:\TestKernalMain\lib\bundled\commons-cli-1.2.jar; 
D:\TestKernalMain\lib\bundled\commons-collections-3.2.1.jar; 
D:\TestKernalMain\lib\bundled\commons-configuration-1.8.jar; 
D:\TestKernalMain\lib\bundled\commons-io-2.0.jar; 
D:\TestKernalMain\lib\bundled\commons-lang-2.5.jar; 
D:\TestKernalMain\lib\bundled\commons-logging-1.1.1.jar; 
D:\TestKernalMain\lib\bundled\commons-net-2.2.jar; 
D:\TestKernalMain\lib\bundled\commons-vfs2-2.0.jar; 
D:\TestKernalMain\lib\bundled\eventbus-1.4.jar; 
D:\TestKernalMain\lib\bundled\javasimon-core-2.3.0.jar; 
D:\TestKernalMain\lib\bundled\javasimon-jmx-2.3.0.jar; 
D:\TestKernalMain\lib\bundled\jpcsc.jar; 
D:\TestKernalMain\tools\ant\ant-antlr.jar; 
D:\TestKernalMain\tools\ant\ant-apache-bcel.jar; 
D:\TestKernalMain\tools\ant\ant-apache-bsf.jar; 
D:\TestKernalMain\tools\ant\ant-apache-log4j.jar; 
D:\TestKernalMain\tools\ant\ant-apache-oro.jar; 
D:\TestKernalMain\tools\ant\ant-apache-regexp.jar; 
D:\TestKernalMain\tools\ant\ant-apache-resolver.jar; 
D:\TestKernalMain\tools\ant\ant-apache-xalan2.jar; 
D:\TestKernalMain\tools\ant\ant-commons-logging.jar; 
D:\TestKernalMain\tools\ant\ant-commons-net.jar; 
D:\TestKernalMain\tools\ant\ant-contrib.jar; 
D:\TestKernalMain\tools\ant\ant-jai.jar; 
D:\TestKernalMain\tools\ant\ant-javamail.jar; 
D:\TestKernalMain\tools\ant\ant-jdepend.jar; 
D:\TestKernalMain\tools\ant\ant-jmf.jar; 
D:\TestKernalMain\tools\ant\ant-jsch.jar; 
D:\TestKernalMain\tools\ant\ant-junit.jar; 
D:\TestKernalMain\tools\ant\ant-junit4.jar; 
D:\TestKernalMain\tools\ant\ant-launcher.jar; 
D:\TestKernalMain\tools\ant\ant-netrexx.jar; 
D:\TestKernalMain\tools\ant\ant-swing.jar; 
D:\TestKernalMain\tools\ant\ant-testutil.jar; 
D:\TestKernalMain\tools\ant\ant.jar; 
D:\TestKernalMain\tools\cardreader\javactapi.jar; 
D:\TestKernalMain\tools\iText\iText-2.1.7.jar; 
D:\TestKernalMain\tools\iText\iText-rtf-2.1.7.jar; 
D:\TestKernalMain\tools\jdiff\antjdiff.jar; 
D:\TestKernalMain\tools\jdiff\jdiff.jar; 
D:\TestKernalMain\tools\jdiff\xerces.jar; 
D:\TestKernalMain\tools\JUnit\junit.jar; 
D:\TestKernalMain\tests\lib\cglib-nodep-2.2.2.jar; 
D:\TestKernalMain\tests\lib\easymock-3.0.jar; 
D:\TestKernalMain\tests\lib\jetm-1.2.3.jar; 
D:\TestKernalMain\tests\lib\jetm-optional-1.2.3.jar; 
D:\TestKernalMain\tests\lib\obj-1.2.jar; 
D:\Workspace\GUITypeTwo\bin; 
D:\TestKernalMain\lib\TestKernel.jar; 
D:\GUITypeTwo\lib\external\docking-frames-core.jar; 
D:\GUITypeTwo\lib\external\docking-frames-common.jar; 
D:\GUITypeTwo\lib\external\glasslib.jar; 
D:\GUITypeTwo\lib\external\docking-frames-ext-glass.jar; 
D:\GUITypeTwo\lib\external\h2-1.3.167.jar; 
D:\GUITypeTwo\lib\external\mydoggy-api.jar; 
D:\GUITypeTwo\lib\external\mydoggy-plaf.jar; 
D:\GUITypeTwo\lib\external\mydoggy-res.jar; 
D:\GUITypeTwo\lib\external\swingx-core-1.6.2.jar; 
D:\GUITypeTwo\lib\external\TableLayout.jar; 
D:\GUITypeTwo\lib\external\ValidationAPI.jar; 
D:\GUITypeTwo\tools\MPlus.jar; 
D:\GUITypeTwo\tools\JUnit\junit-4.9.jar; 
D:\TestKernalMain\config, 
com.gui.typetwo.GuiTypeTwo 

回答

1

/Cstart之前刪除空格和分裂"start /high"成兩個獨立的參數:

new ProcessBuilder("cmd", "/C", "start", "/high", ...) 
+0

它說: 「Windows無法找到-DTESTKERNEL_PROPERTIES =」我交叉檢查,發現文件存在於所需位置 –

+0

'path'的值是什麼?你能首先把所有的過程參數放在一個列表中,打印出來,在原始問題中發佈輸出,然後調用'新的ProcessBuilder(list)'?那裏肯定有一些錯字或其他小問題。 –

+0

參數有適當的值,我試圖使用列表來代替。給出相同的結果。 「Windows找不到.......」 –