我使用以下命令让终端与 SenseRelate::AllWords 一起使用:
wsd.pl --context test.txt --format raw --
但是,现在我尝试从 Java 代码运行 wsd.pl,它看起来像这样:
public static void main(String args[] ) throws IOException {
String line;
ProcessBuilder pb = new ProcessBuilder("wsd.pl", "--context test.txt", "--format raw");
pb.redirectErrorStream(true);
Process process = pb.start();
InputStream stdout = process.getInputStream();
BufferedReader reader = new BufferedReader (new InputStreamReader(stdout));
while ((line = reader.readLine ()) != null) {
System.out.println ("Stdout: " + line);
}
}
它给了我错误:
Stdout: Unknown option: context test.txt
Stdout: Unknown option: format raw
test.txt 路径是项目的源文件夹(顶层,紧邻 src、.git 等)
我尝试了一些不同的方法:将参数添加到列表中并根据该列表创建一个新进程,格式化参数的不同方法,但不行,它不起作用。有人可以帮忙吗?我想这是我不熟悉的语法。
谢谢!
最佳答案
ProcessBuilder pb = new ProcessBuilder("wsd.pl", "--context", "test.txt", "--format", "raw");
还要确保您的工作目录正确。
关于Java:使用 Process() 调用 Perl 脚本:wsd.pl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20217419/