I'm starting Fuseki server through cmd line interface command. Following way;
![My CMD working code]
D:
cd jena-fuseki-1.0.1
fuseki-server --update --mem /ds
How can I run above code through java class without opening any CMD line interface? So many stackoverflow answers provide below code.
Process child = Runtime.getRuntime().exec(command);
But I didn't get how should apply my above things to here.
Updated question;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] command = { "fuseki-server", "--update", "--mem", "/ds" };
File directory = new File("D:\\jena-fuseki-1.0.1");
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(directory);
try {
pb.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} Error message : "java.io.IOException: Cannot run program "fuseki-server" (in directory "D:\jena-fuseki-1.0.1"): CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(Unknown Source)"
You need to put the extension (
.exe
,.bat
, ...) to the fuseki-server command file (the shell does it for you but here you are giving the filename).You also need to use
pb.start()
to actually start the process.