我的WebApplication中運行.exe程序有奇怪的問題。它在控制檯模式下工作正常。Runtime.exec()在tomcat/web應用程序上無法正常工作
我的EXE應用程序代碼:
...
Console.WriteLine("before getEnvirement");
IDictionary environmentVariables = Environment.GetEnvironmentVariables();
foreach (DictionaryEntry de in environmentVariables)
{
Console.WriteLine(" {0} = {1}", de.Key, de.Value);
}
Console.WriteLine("before new Application");
this.application = new App();
Console.WriteLine("after new Application");
...
其中,app()是COM庫類(我說當然是參考)。
我的Java控制檯/ WebApplication的代碼:
before getEnvirement
<all my envirements>
before new Application
after new Application
在 「Web應用模式」(壞)輸出:
before getEnvirement
Path = C:\Windows\system32; <...>
TEMP = C:\Windows\TEMP
在 「控制檯模式」(正確)
try {
String[] callAndArgs = {"C:\\temp\\program.exe", "arg1", "arg2"};
Process p = Runtime.getRuntime().exec(callAndArgs);
p.waitFor();
} catch (IOException e) {
System.out.println("IOException Error: " + e.getMessage());
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
輸出
或者當我刪除getEnvirement代碼(也是壞的):
before getEnvirement
before new Application
EXE應用程序將不會關閉本身在Tomcat(我必須使用任務管理器殺吧)
而且我的問題:爲什麼不到風度工作在Tomcat是否正確?爲什麼exe程序在使用tomcat運行時遇到系統環境問題?最後:爲什麼它在控制檯模式下工作? :)