Hi there,
I was just wondering if/how liburbi Java allows for use of it's classes for executing programs outside of it?
What I'm trying to do is to execute an external Windows command line based program from a liburbi program based on
urbisound, and get the result of the external program saved as a file for the liburbi app to access later. The executable and the files I'm working with are in a separate directory to the one I've launched the liburbi program from.
What I have is something like this (excluding the exception handling I have in place):
Code:
resultFileName = generateResultFileName();
System.out.println("\n"+resultFileName);
String inputStream = null;
//-*- define arguments for the command
command[0] = "my_executable"; //the program (windows .exe)
command[1] = fileName; //a file program above is to use
command[2] = "-l:"+mainPath; //tells program where "fileName" is
System.out.println("Executing:");
System.out.println(command[0]+" "+command[1]+" "+command[2]);
Process p = Runtime.getRuntime().exec(command); //-*- execute command
//-*- buffer the stdin and stderr
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
//-*- write to a file:
System.out.println("Writing to file :"+resultFileName+"\n"); //resultFileName declared above
PrintWriter outFile = new PrintWriter
(new FileWriter(mainPath+resultFileName)); //mainPath is for processed files
System.out.println("Results + file save \n");
while ((inputStream = stdInput.readLine()) != null)
{
System.out.println(inputStream);
outFile.println(inputStream);
}
outFile.close();
System.out.println("file written to as "+resultFileName);
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((inputStream = stdError.readLine()) != null)
{
System.out.println(inputStream);
}
However when executing the program it doesn't seem to make any progress past the line:
Code:
System.out.println("Results + file save \n");
Any ideas as to what could be causing the hang (or what I perceive to be one)?
Thanks
Andrew
Edit: I apologise that I had "fileName" also used for the output file, which isn't what I have in the code, so I've corrected it here.