• 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

Executing sh command from Java

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm generating a tar file from my java program which is executed from database(Oracle 10g).I'm using the Runtime.
aixCommand ="tar -cvf ccc.tat ccc.dat"
String[] aixCmds = new String[]{"sh", "-c", aixCommand };
I'm getting the following Exception :
java.io.IOException: can't exec:sh doesn't exist

Please help me out
Thanks in advance
Sujith
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Runtime.exec doesn't create the same kind of environemnt you have at the command line. Try something like "/usr/bin/sh" instead of "sh". It might also be better to break up the tar command into its separate pieces, so that the overall command is something like

new String[] {"sh", "-c", "tar", "-cvf", "ccc.tat", "ccc.dat" }

Here is an article that explains some of the pitfalls of using Runtime.exec.
 
Sujith Kanaparthi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dittmer,

As per your advice I used "/bin/sh"(as I located sh in /bin instead of /usr/bin) instead of "sh" and also broke the tar commang into separate pieces.I got no error but the tar file is not getting generated.But when run the same tar command on linux it's working fine.

Thanks,
Sujith
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is true for sh (you have to give the whole path) is true for tar too.
 
Sujith Kanaparthi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stephen,

Thanks for your advice.I'm sure I can run the tar command from my programm.

Regards,
Sujith
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic