[英]launch an external installer app in Mac from Java
我正在用Java創建一個小型應用程序,需要通過CD在Mac和Windows中使用它。
此應用程序的基本思想是擁有一個主菜單(Mac和Windows有所不同),您可以在其中選擇多個選項(安裝應用程序,查看CD的內容,查看幫助手冊...等)。公司徽標...等
Windows和Mac中要安裝的應用程序將有所不同。
我要做的是啟動外部安裝程序,安裝完成后,我要啟動該應用程序。
我的主要問題是,在不同的過程中啟動安裝程序后,waitfor()返回有效的exitvalue並繼續。
我想等到此應用程序完全安裝后再嘗試運行它。
對於Windows
Runtime.getRuntime().exec(" \"c:/.../ExternalAppforWin.exe\"");
對於Mac
File instFolder = new File(System.getProperty("user.dir") + "ExternalAppforMac.pkg")
Process p = Runtime.getRuntime().exec(new String[] { "open", instFolder.toString() });
int exitVal = p.waitFor();
if (exitVal==0)
...
你可以幫幫我嗎?
謝謝。
似乎您需要檢查系統上是否存在安裝窗口,而不是可執行文件。 據我所知,Java中沒有獨立於系統的方法來執行此操作,但是通過使用功能強大的庫(如sun的JNA(在Windows和Mac上均受支持,可以在此處找到)),可以通過適當的方法來執行此操作OS API調用。
這是您可能要在Windows上執行的示例,mac調用應類似:
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
.
.
.
//execute process
Process p = Runtime.getRuntime().exec(" \"c:/.../ExternalAppforWin.exe\"");
//wait for return value
int res = p.waitFor();
//if we have a valid return code begin waiting for window to be closed
if(res == 0)
{
//define a window handle variable
WinDef.HWND windowHandle = null;
do
{
//sleep a little while before polling the value
try{Thread.sleep(100);}catch(InterruptedException e){}
//try to fetch the window by title
windowHandle = User32.INSTANCE.FindWindow(null, "<Window Title>");
//if the handle is not null, the window is still open so sleep and then try try again
}while(windowHandle != null && windowHandle.getPointer() != Pointer.NULL);
//continue on with your code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.