如何通过Java在PowerShell_ISE.exe中运行.ps1文件

如何通过Java在PowerShell_ISE.exe中运行.ps1文件,java,eclipse,powershell,scripting,Java,Eclipse,Powershell,Scripting,因此,我正在用java创建一个GUI,通过powershell启动各种不同的脚本。我已经能够编写一个命令,在powershellISE中打开.ps1文件,但脚本实际上没有运行。我的代码如下: String [] str = {"cmd", "/c" "start", "powershell_ise.exe", "-file", "myPath"}; try{ Runtime.getRuntime().exec(str); } catch (IOException e) { e.p

因此,我正在用java创建一个GUI,通过powershell启动各种不同的脚本。我已经能够编写一个命令,在powershellISE中打开.ps1文件,但脚本实际上没有运行。我的代码如下:

String [] str = {"cmd", "/c" "start", "powershell_ise.exe", "-file", "myPath"};
try{
    Runtime.getRuntime().exec(str);
} catch (IOException e) {
    e.printStackTrace();
}
我发现这个问题很有帮助:

但它并没有解决我实际运行脚本的问题


非常感谢

Windows PowerShell集成脚本环境(ISE)是一种图形化主机应用程序,可用于读取、写入、运行、调试和测试脚本


如果要运行已知可用的脚本,可以尝试将
powershell_ise.exe
替换为
powershell.exe
。应该有帮助。

为什么通过ISE?有些脚本需要在运行之前编辑Excel文档,因此有些脚本将在ISE中打开,然后在文档更新后运行。通过powershell.exe启动会更容易吗?谢谢!下面这行代码最终为我实现了:Runtime.getRuntime().exec(“cmd/c start powershell-file”+pathToFileInQuotes);