System Command Within Java Solution
2015-01-13azim58 - System Command Within Java Solution
Hey CPP C Java expert,
I found the solution about how to call system commands from any directory
to call any program. Thanks again for taking the time to look at this
with me. I apologize if I came across as impatient or anything. Your time
was appreciated :) . Here is my code below. It works!
String path = "W:\\Groups\\Zombie Edutainment\\Zombie Edutainment
Project\\cDNA_lib";
String command = "blastn -db Seq_DB -query cDNA_library.fa -out
screening_out_v6_4.txt -outfmt 6 -evalue 0.0001 -perc_identity 95.0
- num_alignments 10";
try
ProcessBuilder launcher = new ProcessBuilder();
Map<String, String> environment = launcher.environment();
launcher.redirectErrorStream(true);
launcher.directory(new File(path));
environment.put("name", "var");
launcher.command(commandArray);
Process p = launcher.start(); And launch a new process
BufferedReader output = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line;
while ((line = output.readLine()) != null)
System.out.println(line);
The process should be done now, but wait to be sure.
p.waitFor();
catch(IOException e1)
}
catch(InterruptedException e2) {
System.out.println("Process: " + commandArray0 + " is done");
}
Good luck with everything! I'll assume that I don't need to pay anything
since we didn't find a solution together. Nevertheless, your attempts
were appreciated, and maybe the solution I have given you here will be of
use to you someday.
Best regards,
azim58
===========================================================================
Note that in order for Java to give a command line command to call the
program, the program must be part of the systems path.
see environment variable path