为了账号安全,请及时绑定邮箱和手机立即绑定

Java Runtime.exe()不返回PowerShell命令输出

Java Runtime.exe()不返回PowerShell命令输出

狐的传说 2021-04-06 21:20:54
我尝试使用Java Runtime.exe在命令下方运行String command ="powershell (Get-item  \"D:\\test\" ).creationtime.ToString(\"yyyy-MM-dd'T'HH:mm:ss\")";当我在Windows命令提示符上运行它时,它返回“ 2017-08-07T20:03:00”。但是,当我在myMethod中运行该程序时,该程序也正在运行,并且什么也没有返回给我。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;}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 337 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信