DataInputStream java-程序不';调用dis.close()后t结束,然后system.exit(0)。仅在.exe上发生

DataInputStream java-程序不';调用dis.close()后t结束,然后system.exit(0)。仅在.exe上发生,java,jar,exe,datainputstream,Java,Jar,Exe,Datainputstream,我在这里发现了一些异常现象 节目信息: 该程序是一个解析器。它通过数据输入流接收数据。然后,当数据输入流关闭时,我调用system.exit(0) 我已经创建了一个jar和exe。当我使用这个罐子时,它似乎运转良好。一切如期而至。控制台看起来像这样 /the/path/that/im/currently/in $ <I type:> java -jar myprogram.jar commandLineArg *enter

我在这里发现了一些异常现象

节目信息: 该程序是一个解析器。它通过数据输入流接收数据。然后,当数据输入流关闭时,我调用system.exit(0)

我已经创建了一个jar和exe。当我使用这个罐子时,它似乎运转良好。一切如期而至。控制台看起来像这样

 /the/path/that/im/currently/in
 $      <I type:>    java -jar myprogram.jar commandLineArg     *enter
                     Program output
                     Program output
                     Program output
 <program ends and goes back to>
 /the/path/that/im/currently/in
 $
/the/path/that/im/current/in
$java-jar myprogram.jar commandLineArg*输入
程序输出
程序输出
程序输出
//path/that/im/current/in
$
当我使用exe时。控制台看起来像这样,你可以看到它是如何反弹的

 /the/path/that/im/currently/in
 $     <I type:>    ./myprogram commandLineArg       *enter
 /the/path/that/im/currently/in
 $                  Program output
                    Program output
                    Program output
 <now stuck hanging until I hit enter or ctrl+c>     *enter

 /the/path/that/im/currently/in
 $ <now i'm back where I should be>
/the/path/that/im/current/in
$./myprogram commandLineArg*输入
//path/that/im/current/in
$程序输出
程序输出
程序输出
*进入
//path/that/im/current/in

$这听起来像是您用来生成
.exe
文件的工具的问题,它可能不再使用Java虚拟机来执行代码,或者使用一个不适当的虚拟机,因为
系统.exit(0)
调用未被识别为同时退出包装进程的命令,正如Javadocs所述:

公共静态无效退出(int状态)

终止当前运行的Java虚拟机。争论 用作状态代码;按照惯例,非零状态代码 表示异常终止

此方法在类运行时中调用exit方法。这种方法永远不会成功 正常返回

呼叫系统退出(n)实际上等同于呼叫:

 Runtime.getRuntime().exit(n)
因此,可能值得尝试另一个包装工具。


当然,我们不能透露你的情况,除非我们对这个项目有更多的了解。但是我怀疑一个黑客/快速修复方法是在调用exit()之前放置一个
线程.sleep(3000)

请告诉我们
/myprogram
是什么。如果是shell脚本,则显示该脚本的行;如果它是一个编译过的程序,提供它的代码。你说它是极端的,但它仍然不起作用。我相信上述答案似乎更有可能。
 Runtime.getRuntime().exit(n)