java - 如何在 Linux 操作系统中从 Java 调用“Powershell 脚本文件”
问题描述
班级:-
======================
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class TestPowershell {
public static void main(String[] args) throws IOException
{
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("cmd powershell \"\\Test\\Powershell\\powershell.ps1\" ");
proc.getOutputStream().close();
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr);
String line;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
reader.close();
proc.getOutputStream().close();
}
}
我正在尝试通过在 linux 环境中使用 java 来执行 powershell 文件,我遇到了异常(上面我附加了类和异常),请提供一个可以在 linux 中执行 powershell 脚本文件的测试类。提前致谢
解决方案
感谢您的所有回答。
最后,我知道在使用 PowerShell 时,我们应该在 Windows 操作系统中运行脚本,因为微软是 PowerShell 的所有者,他们在 Windows 操作系统中提供了更多功能。
我所做的是,我在 Windows 操作系统中运行脚本并生成了一个 CSV 文件并保存在 SFTP 文件夹中,通过使用 java 我加载了我的文件并处理了我的下一个进程。
推荐阅读
- swift - 如何在 NSTextView 富文本视图 (.rtf) 上启用段落工具
- typescript - 我应该在这个泛型混乱中指定什么签名?
- reactjs - UserProvider 中初始化的空数组未显示在状态或上下文的挂钩中
- woocommerce - 从 woocommerce 触发 twilio 流的 URL
- c++ - (C++) 使用 Cinder 编译项目时出错
- node.js - 如何触发strapi中更新对象的所有相关对象的事件
- arrays - 如何按值从数组中删除对象?
- codeigniter - Codeigniter 从库类调用未定义的方法错误
- haskell - 当没有绑定时,haskell 中缺乏多态推断
- excel - 通过 VBA 将公式写入 Excel 计划