• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 43028
76
  • 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
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic