• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic