【问题标题】:How to run a .ps1 file in PowerShell_ISE.exe through Java如何通过 Java 在 PowerShell_ISE.exe 中运行 .ps1 文件
【发布时间】:2017-12-09 18:47:35
【问题描述】:

所以我在 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();
}

我发现这个问题很有帮助:

Powershell open window (from Java.Runtime.exec)

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

非常感谢!

【问题讨论】:

  • 为什么要通过 ISE?
  • 有些脚本需要在运行之前编辑 Excel 文档,因此有些脚本会在 ISE 中打开,然后在文档更新后运行。通过powershell.exe启动会不会更方便?

标签: java eclipse powershell scripting


【解决方案1】:

Windows PowerShell 集成脚本环境 (ISE) 是一个图形主机应用程序,使您能够读取、写入、运行、调试和测试脚本。

如果您想运行您知道有效的脚本,您可以尝试将powershell_ise.exe 替换为powershell.exeHow to run powershell in cmd 应该会有所帮助。

【讨论】:

  • 谢谢!以下行最终对我有用: Runtime.getRuntime().exec("cmd /c start powershell -file " + pathToFileInQuotes);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 2016-12-21
  • 1970-01-01
  • 1970-01-01
  • 2013-07-17
  • 2013-10-02
相关资源
最近更新 更多