我嘗試使用Java Runtime.exe在命令下方運(yùn)行String command ="powershell (Get-item \"D:\\test\" ).creationtime.ToString(\"yyyy-MM-dd'T'HH:mm:ss\")";當(dāng)我在Windows命令提示符上運(yùn)行它時(shí),它返回“ 2017-08-07T20:03:00”。但是,當(dāng)我在myMethod中運(yùn)行該程序時(shí),該程序也正在運(yùn)行,并且什么也沒有返回給我。myMethode:private static void executePowerShellCommand(String command) { String line = ""; command = "cmd /c " + command; try { Process process = Runtime.getRuntime().exec(command); process.getOutputStream().close(); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); while ((line = reader.readLine()) != null) { System.out.println(line); } reader.close(); System.out.println("Done"); } catch (java.io.IOException e) { e.printStackTrace(); } return;}
添加回答
舉報(bào)
0/150
提交
取消