Running Command Line Scripts From Java

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hal Vaughan

    Running Command Line Scripts From Java

    I'm having trouble with a bash script (in Linux) I'm running from Java. It
    works -- some of the time, but I can't determine exactly why it works 1
    time and doesn't work the next 4-5 times.

    I'm not sure, but the script seems more likely to work if I run it directly
    from bash. I was thinking of running a small script and, within the
    script, calling bash directly to execute the program, something like:

    #!/bin/bash
    bash /usr/local/myprog/setup

    I know Java runs the command on its own, so it isn't using bash or any other
    shell. Will this force my setup program to be run under bash? Are there
    any side effects or considerations that might not be obvious to a
    self-taught coder?

    Thanks for any insight or feedback on this problem!

    Hal
  • hiwa

    #2
    Re: Running Command Line Scripts From Java

    Hal Vaughan <hal@thresholdd igital.com> wrote in message news:<gB09c.127 41$JO3.20875@at tbi_s04>...[color=blue]
    > I'm having trouble with a bash script (in Linux) I'm running from Java. It
    > works -- some of the time, but I can't determine exactly why it works 1
    > time and doesn't work the next 4-5 times.
    >
    > I'm not sure, but the script seems more likely to work if I run it directly
    > from bash. I was thinking of running a small script and, within the
    > script, calling bash directly to execute the program, something like:
    >
    > #!/bin/bash
    > bash /usr/local/myprog/setup
    >
    > I know Java runs the command on its own, so it isn't using bash or any other
    > shell. Will this force my setup program to be run under bash? Are there
    > any side effects or considerations that might not be obvious to a
    > self-taught coder?
    >
    > Thanks for any insight or feedback on this problem!
    >
    > Hal[/color]

    Runtime.getRunt ime().exec(new String[] {"/bin\sh", "-c", "myscript"} );

    Comment

    Working...