Executing PowerShell Commands in Java Program

前端 未结 4 1752
醉梦人生
醉梦人生 2020-11-30 07:08

I have a PowerShell Command which I need to execute using Java program. Can somebody guide me how to do this?

My command is Get-ItemP

4条回答
  •  一生所求
    2020-11-30 07:36

    you can try to calle the powershell.exe with some commands like :

    String[] commandList = {"powershell.exe", "-Command", "dir"};  
    
            ProcessBuilder pb = new ProcessBuilder(commandList);  
    
            Process p = pb.start();  
    

提交回复
热议问题