0

So I am creating a GUI in java that launches a variety of different scripts through powershell. I have been able to write a command that opens the .ps1 file in powershellISE, but the script doesn't actually run. My code is as follows:

String [] str = {"cmd", "/c" "start", "powershell_ise.exe", "-file", "myPath"};
try{
    Runtime.getRuntime().exec(str);
} catch (IOException e) {
    e.printStackTrace();
}

I found this question to be helpful:

Powershell open window (from Java.Runtime.exec)

But it did not solve my issue of actually running the script

Thanks so much!

Jacob Russell
  • 53
  • 2
  • 12

1 Answers1

0

Windows PowerShell Integrated Scripting Environment (ISE) is a graphical host application that enables you to read, write, run, debug, and test scripts.

If you want to run scripts you know work, you might try replacing powershell_ise.exe with powershell.exe. How to run powershell in cmd should help.

Paul Sturm
  • 2,118
  • 1
  • 18
  • 23
  • Thanks! The following line ended up working out for me: Runtime.getRuntime().exec("cmd /c start powershell -file " + pathToFileInQuotes); – Jacob Russell Jul 07 '17 at 19:36