例如,要dir通过 cmd 执行命令,并使控制台保持打开状态,您需要这样写:
Runtime.getRuntime().exec("cmd /c start cmd /k dir");
如何用 powershell 做同样的事情?尝试了以下以及更多,但没有成功:
Runtime.getRuntime().exec("powershell /c start cmd /k dir"); // нет
Runtime.getRuntime().exec("powershell start powershell dir"); // команду выполняет, но закрывает окно, а как параметр добавить неопнятно
Runtime.getRuntime().exec("powershell start powershell -noexit dir"); // нет
Runtime.getRuntime().exec("powershell start powershell -noexit -command dir"); // нет
Runtime.getRuntime().exec("powershell -command start powershell -noexit -command dir"); // нет
Runtime.getRuntime().exec("powershell start powershell \"-noexit\", \"-command {dir}\""); // нет
Runtime.getRuntime().exec("powershell start powershell \"-noexit\", \"-command {dir}\""); // нет
Runtime.getRuntime().exec("powershell \"-command start powershell '-noexit', '-command dir'\""); // нет
Runtime.getRuntime().exec("powershell -command {start powershell \"-noexit\", \"-command dir\"}"); // нет