【发布时间】:2012-03-05 17:45:57
【问题描述】:
在我的 WebApplication 中运行 .exe 程序时遇到奇怪的问题。它在控制台模式下运行良好。
我的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 代码:
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());
}
“控制台模式”下的输出(正确):
before getEnvirement
<all my envirements>
before new Application
after new Application
“Web 应用程序模式”下的输出(错误):
before getEnvirement
Path = C:\Windows\system32; <...>
TEMP = C:\Windows\TEMP
或者当我删除 getEnvirement 代码时(也不好):
before getEnvirement
before new Application
exe应用程序不会在tomcat上自行关闭(我必须使用任务管理器来杀死它)
还有我的问题:为什么它在 tomcat 上不能正常工作?为什么exe程序在tomcat上运行时无法获取系统环境?最后:为什么它在控制台模式下工作? :)
【问题讨论】:
标签: java web-applications tomcat