powershell - 如何从 Kotlin 运行 PowerShell 脚本?

标签 powershell kotlin

如何使用 Kotlin 运行 Powershell 脚本?

我试图移植一些我在 StackOverflow 上找到的 Java 代码,但我无法让它工作。我还尝试了以下方法:

Runtime.getRuntime().exec("powershell.exe [path to file]")

但这也不起作用。

在 Kotlin 中执行此操作的最简单方法是什么?

最佳答案

请添加“-File”参数,例如脚本应该是这样的:

Runtime.getRuntime().exec("powershell.exe -File d:\\my-script.ps1")

请参阅PowerShell documentation here .

关于powershell - 如何从 Kotlin 运行 PowerShell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52684385/

相关文章:

Powershell:如何安装 cmdlet?

.net - 使用 PowerShell 或批处理文件从 FTP 服务器删除超过 X 天的文件

powershell - 使用PowerShell卸载ClickOnce应用程序?

android - 如何设置点击计时器?

android - 如何使用 Android Studio 为 newInstance Fragments 创建一个 kotlin live 模板

postgresql - 查询 : JpaRepository 的验证失败

spring - Kotlin 和 Spring MVC - HTTP 状态 400 - 空

json - 从xml文档/Powershell/控制数组格式生成JSON

powershell - 使用PowerShell删除CSV中的前两列

spring - 使用Spring Boot运行单元测试, “no runnable methods”错误