Page 1 of 1

how to execute commands in servlets

Posted: Wed Oct 06, 2010 1:12 pm
by tinnumaverick
I have an ingest command which i need to run to ingest objects into fedora repository.
The command is

/srv/fedora/client/bin/fedora-ingest.sh f SIUImages_bike.xml info:fedora/fedora-system:FOXML-1.1 test.lib.siu.edu:8080 fedoraAdmin fedoraAdmin http

I want to execute this command in a servlet...

I had tried

try {
Runtime rt = Runtime.getRuntime();

Process pr = rt.exec("/srv/fedora/client/bin/fedora-ingest.sh f SIUImages_bike.xml info:fedora/fedora-system:FOXML-1.1 test.lib.siu.edu:8080 fedoraAdmin fedoraAdmin http");

BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

String line=null;

while((line=input.readLine()) != null) {
out.println(line);

}

int exitVal = pr.waitFor();
out.println("This is Exited with error code "+exitVal);

}
catch(Exception e) {
out.println(e.toString());
e.printStackTrace();
}

I had tried this but the command was not executed successfully. It showed me a message "This is Exited with error code 0".

My question is

the file(SIUImages_bike.xml) which i am using in the command is located at path "/srv/fedora/tomcat/webapps/formC/WEB-INF/classes/FOXML"

now i want to use
Process pr = rt.exec(" FILE PATH HERE /srv/fedora/client/bin/fedora-ingest.sh f SIUImages_bike.xml info:fedora/fedora-system:FOXML-1.1 test.lib.siu.edu:8080 fedoraAdmin fedoraAdmin http");

but i already have a "srv" in the command
Process pr = rt.exec(" /srv/fedora/tomcat/webapps/formC/WEB-INF/classes/FOXML /srv/fedora/client/bin/fedora-ingest.sh f SIUImages_bike.xml info:fedora/fedora-system:FOXML-1.1 test.lib.siu.edu:8080 fedoraAdmin fedoraAdmin http;