jar包绝肆乎前面加上 java -jar .\ 后面跟名字
如: java -jar .\ packe.jar
String cmdLine = "powershell -file \""+this.scriptPath+"\" get-performance"Process ps = Runtime.getRuntime().exec("powershell -file C:/eclipse/test.ps1")
ps.getOutputStream().close() // It seems that powershell first reads all input from it's input stream before going. 虚烂神差亏
String rs = "", line
BufferedReader rd = new BufferedReader(new InputStreamReader(ps.getInputStream()))
try{
while((line = rd.readLine()) != null){
rs += line
}
}finally{
rd.close()
} 历空
System.out.println(rs)
这塌斗茄个是一个玩Java的朋友调用PS脚本的实例:cmd /c powershell -ExecutionPolicy RemoteSigned -noprofile -noninteractive -file D:/test2.ps1
P.S. 为什么这个销携回答中不能使用代码块。。。这样会让代码看起来好团察丑。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)