我想在我的JFrame GUI中运行一个基于Linux的可执行文件src2srcml,它采用源文件(C,C++,Java)并将其转换为要使用的XML文件后来。我的GUI成功使用JFileChooser来定位和选择源文件。从JFrame(linux)(日食)运行可执行文件
我目前正在尝试使用Runtime.getRuntime().exec()函数来运行可执行文件,但到目前为止没有任何事情发生。我可以使用命令“bash-4.1 $ ./src2srcml --position sum_avg.c -o hooray.c.xml”从命令行运行它,它将源文件sum_avg.c转换为新的XML文件文件hooray.c.xml,但是当我在Runtime.getRuntime().exe()中尝试完全相同的命令时,没有任何反应。我对Runtime.getRuntime()。exec()或ProcessBuilder类不是特别熟悉。我是否需要导航到可执行文件的第一个位置?我也尝试在第一个参数中包含路径,对自己的可执行文件的调用,但也没有工作。
//--- 'Run Source Code' Button---//
JButton btnRunSourceCode = new JButton("Run Source Code");
btnRunSourceCode.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(filePath == null){
textArea.setText("Please Load a source file (C, C++, Java)");
}
try{
textArea.setText("Converting Source Code to XML");
String[] commands = {"./src2srcml", "--position ", selectedFile.getName(), " -o targetFile.xml"};
Process src2XML = Runtime.getRuntime().exec(commands);
src2XML.waitFor();
}
catch(Exception exc){/*src2srcml Fail*/}
}
});
btnRunSourceCode.setBounds(612, 39, 156, 25);
contentPane.add(btnRunSourceCode);
当前可执行文件位于我的项目(Eclipse)的工作区中。当我完成所有工作时,我想将整个程序编译为一个可执行文件,以便将src2srcml嵌入到我的可执行文件中,而不需要单独执行。这可能吗?
在此先感谢您的任何想法!