I am trying to run a linux based executable called src2srcml in my JFrame GUI that takes a source file (C, C++, Java) and converts it to an XML file to be used later. My GUI successfully uses the JFileChooser to locate and select the source file.
I'm currently trying to use the Runtime.getRuntime().exec() function to run the executable but so far nothing is happening. I can run it from the command line using the commands "bash-4.1$ ./src2srcml --position sum_avg.c -o hooray.c.xml", which takes the source file sum_avg.c, converts it to XML in a new file hooray.c.xml but when I try the exact same commands in Runtime.getRuntime().exec() nothing happens. I'm not particularly familiar with the Runtime.getRuntime().exec() or ProcessBuilder classes. Do I need to navigate to where the executable is first? I also tried including the path in the first parameter, the call to the executable its self but that didn't work either.
//--- '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);
Currently the executable is in the workspace of my project (Eclipse). when I get everything working I would like to compile the whole program into a single executable so that the src2srcml is embedded into my executable and isn't required separately. Is this possible?
Thanks in advance for any ideas!