• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to execute commands in servlets

 
tinnu maverick
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch! Please => UseCodeTags when you post a code snap!
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, an exit status of 0 means that the command was executed successfully. If the command isn't producing the results you are expecting, then maybe there is something wrong with your command syntax or with your shell script.

Try using the absolute path of "SIUImages_bike.xml" instead of just its file name.
 
tinnu maverick
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Angstadt wrote:Actually, an exit status of 0 means that the command was executed successfully. If the command isn't producing the results you are expecting, then maybe there is something wrong with your command syntax or with your shell script.

Try using the absolute path of "SIUImages_bike.xml" instead of just its file name.



Thank you so much Michael Angstadt!! I had forgotten to give the absolute path while executing the command. Thanks again!! Gained new energy after solving this problem!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic