• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to execute commands in servlets

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch! Please => UseCodeTags when you post a code snap!
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic