如何从Kotlin运行PowerShell脚本? [英] How to run PowerShell scripts from Kotlin?

查看:100
本文介绍了如何从Kotlin运行PowerShell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Kotlin运行Powershell脚本?

How can I run a Powershell script using Kotlin?

我试图移植一些我在StackOverflow上找到的Java代码,但是我无法使其正常工作.我还尝试了以下方法:

I tried to port some Java code I found on StackOverflow, but I couldn't get it to work. I also tried the following:

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

但是那也不起作用.

在Kotlin中最简单的方法是什么?

What is the simplest way to do this in Kotlin?

推荐答案

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

Please add "-File" argument, e.g. script should be like this:

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

请参阅此处是PowerShell文档.

这篇关于如何从Kotlin运行PowerShell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆