469,946 Members | 1,992 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

output from executing external programm

Dear all,

I am a newbie in Java, I got the following problem:
I am going through a list of directories. The programm looks inside each directory for specific files and writes them in an File-array. Then it goes through this array and executes the external programm "naccess". naccess takes a file as input and produces 4 output files. Unfortunatly the result files are not in the directory where the input file is (/home/tj/test), they are in the java directory (/home/tj/workspace/Set).
Is there a way to tell java to execute the programm in the acutal folder?
I paste some of the source code, hope it is not to much/less:

public void scanDir(File filePath){

//Just get zipped Files
FileExtensionFilter filter = new FileExtensionFilter(".pdb");

String[] entries = filePath.list(filter);

//entry contains no files
if (entries == null || entries.length < 1){
return;
}
//go through file list
for (int i = 0 ; i < entries.length ; i++){

File entry = new File(filePath, entries);

if (entry.isDirectory()){
scanDir(entry);
}else{
String[] programm = {"/bin bash -c '/home/tj/naccess'", entry.getAbsolutePath()};
positivSet.execute(programm);
}//else scanDir()
}//for
}//scanDir()

//positiveSet.execute is pretty much an adaption of the streamgobbler class which can be found here:
http://www.javaworld.com/javaworld/j...229-traps.html

Sadly there is no switch in naccess to redirect the output, it always writes the result files in the executing folder.

Thanks very much,
Thomas
Aug 18 '06 #1
2 1702
PLA
44
Make a shell including the change to the good directory and the call to naccess, then call this shell in your program instead of naccess.

May that help

Pascal
Aug 23 '06 #2
I finally fixed the problem with giving the actual working directory to runtime.exec. But thanks for your help, keep this in mind!

Cheers,
Thomas
Aug 24 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Avi Kak | last post: by
3 posts views Thread by Yuan HOng | last post: by
83 posts views Thread by deppy_3 | last post: by
20 posts views Thread by Ilias Lazaridis | last post: by
2 posts views Thread by qwertycat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.