Java运行时:窗口启动的进程未打开

Java运行时:窗口启动的进程未打开,java,glassfish,runtime.exec,Java,Glassfish,Runtime.exec,我使用glassfish服务器运行java web应用程序(在windows 7 64位、jdk 1.7.0.67上)。我正试着从课堂上推出putty。进程已启动(我可以在windows的任务管理器中看到),但没有打开putty窗口。。。我尝试了不同的代码,如: Process p = Runtime.getRuntime().exec( "rundll32 SHELL32.DLL,ShellExec_RunDLL " + "C:\\putty.exe"); 或 或 glassfish中的安全

我使用glassfish服务器运行java web应用程序(在windows 7 64位、jdk 1.7.0.67上)。我正试着从课堂上推出putty。进程已启动(我可以在windows的任务管理器中看到),但没有打开putty窗口。。。我尝试了不同的代码,如:

Process p = Runtime.getRuntime().exec( "rundll32 SHELL32.DLL,ShellExec_RunDLL " + "C:\\putty.exe");

glassfish中的安全管理器已禁用。putty.exe被标记为以管理员身份执行。该方法与其他应用程序相同:cmd.exe或pspade.exe。如果我在应用程序启动的cmd.exe中执行代码,则代码执行良好。 我不知道,你的帮助会很好的

编辑

在这种情况下不起作用,但在其他情况下可能会有所帮助

尝试添加:

try (BufferedReader reader = new BufferedReader(new inputStreamReader(process.getInputStream()));){            
  while (reader.readLine() != null){
        // consume the InputStream of the shell command
  } catch (IOException e) {
     //might throw an Exception if reader is not closed properly
  }

在exec()命令之后。也许putty会向控制台输出一些东西,当缓冲区已满时,Shell将停止执行程序。因此,如果未正确使用
InputStream
,shell将只等待,什么也不做,但进程将启动。

对我来说,您的代码正在工作。将您的
putty.exe
放入任何其他驱动器并进行检查。我将其放在D:,相同的…有关正确创建和处理进程的许多好提示,请参见。然后忽略它引用
exec
,并使用
ProcessBuilder
创建流程。此外,将参数
String
分解为参数
String[]
,以便更可靠地解析路径(除其他外)…使用此代码,应用程序将停留在while循环中,永远不会退出。但是没有读到任何一行。啊,很值得一试。例如,解压时它确实帮助了我。
Process p = Runtime.getRuntime().exec(cmd /c start C:\\putty.exe");
try (BufferedReader reader = new BufferedReader(new inputStreamReader(process.getInputStream()));){            
  while (reader.readLine() != null){
        // consume the InputStream of the shell command
  } catch (IOException e) {
     //might throw an Exception if reader is not closed properly
  }