URBI Forum

http://www.urbiforge.com
It is currently Fri Sep 03, 2010 8:11 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Executing Processes under liburbi Java
PostPosted: Thu May 04, 2006 1:59 pm 
Offline

Joined: Thu Jan 19, 2006 3:04 pm
Posts: 12
Location: School of MACS. Heriot Watt Uni, Scotland.
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group