我試圖在Mac上運行Java上的「tar」命令。我注意到這個命令被卡住了。基本上,文件大小不會增長,命令也不會返回。但是,如果我運行較小的directiry,它工作正常。使用Java的Mac(Unix)上運行命令 - 卡住
這裏是我的代碼:
try
{
Runtime rt = Runtime.getRuntime();
Process process = new ProcessBuilder(new String[]{"tar","-cvzf",compressFileName+" "+all_dirs}).start();
InputStream stdin2 = process.getInputStream();
InputStreamReader isr2 = new InputStreamReader(stdin2);
BufferedReader br2 = new BufferedReader(isr2);
String line2 = null;
System.out.println("<OUTPUT>");
while ((line2 = br2.readLine()) != null)
System.out.println(line2);
System.out.println("</OUTPUT>");
int exitVal3 = process.waitFor();
System.out.println("Process exitValue .....: " + exitVal3);
} catch (Throwable t)
{
t.printStackTrace();
}
我也試過:
String tile_command="tar -cvzf file.tar.gz dire_to_compress ";
String[] tile_command_arr= new String[]{"bash","-c",tile_command};
try
{
Runtime rt = Runtime.getRuntime();
Process proc2 = rt.exec(tile_command_arr);
InputStream stdin2 = process.getInputStream();
InputStreamReader isr2 = new InputStreamReader(stdin2);
BufferedReader br2 = new BufferedReader(isr2);
String line2 = null;
System.out.println("<OUTPUT>");
while ((line2 = br2.readLine()) != null)
System.out.println(line2);
System.out.println("</OUTPUT>");
int exitVal3 = process.waitFor();
System.out.println("Process exitValue for tiling .....: " + exitVal3);
} catch (Throwable t)
{
t.printStackTrace();
}
目錄有多大?您的JVM僅限於多少內存? – alfasin
對於任何目錄,這看起來好像根本不應該工作。你確定你獲得了*任何*輸入的零退出值嗎? – RealSkeptic
目錄大小爲10GB ...我運行Java時未指定內存參數 – user836026