calling a bash script but cannot get out

Discussion in 'Java' started by charly, Dec 7, 2003.

  1. charly

    charly Guest

    Hi !

    I'm working on a website which can generate a dump of a database. I
    generate csv files then tar and zip them and redirect the browser to the
    file.

    The problem is that I cannot get out of the process I create :

    String dest ="/bin/tar -cz " + SaveDir + "*.csv -f " + SaveDir + nomZip
    + " & exit";
    String[] commande = { "/bin/bash", "-c", dest };

    System.out.println(" Saving...);
    Process process = Runtime.getRuntime().exec(commande);

    /*BufferedReader inputreader =
    new BufferedReader(
    new InputStreamReader(process.getInputStream()));
    BufferedReader errorreader =
    new BufferedReader(
    new InputStreamReader(process.getErrorStream()));
    String readerdata;

    while ((readerdata = inputreader.readLine()) != null) {
    System.out.println("On stdout: " + readerdata);
    }
    while ((readerdata = errorreader.readLine()) != null) {
    System.out.println("On stderr: " + readerdata);
    }*/

    But Tomcat tells me : process hasn't exited

    But I issued a exit command so what's happening ?

    Hope to get some help from you folks :)
    charly, Dec 7, 2003
    #1
    1. Advertising

  2. charly

    Sudsy Guest

    charly wrote:
    > Hi !
    >
    > I'm working on a website which can generate a dump of a database. I
    > generate csv files then tar and zip them and redirect the browser to the
    > file.
    >
    > The problem is that I cannot get out of the process I create :
    >
    > String dest ="/bin/tar -cz " + SaveDir + "*.csv -f " + SaveDir + nomZip
    > + " & exit";

    ^^^^^^^
    Get rid of the superfluous stuff. It's not even the correct syntax!
    Sudsy, Dec 7, 2003
    #2
    1. Advertising

  3. charly

    Sudsy Guest

    Sudsy wrote:
    > charly wrote:
    >
    >> Hi !
    >>
    >> I'm working on a website which can generate a dump of a database. I
    >> generate csv files then tar and zip them and redirect the browser to
    >> the file.
    >>
    >> The problem is that I cannot get out of the process I create :
    >>
    >> String dest ="/bin/tar -cz " + SaveDir + "*.csv -f " + SaveDir +
    >> nomZip + " & exit";

    >
    > ^^^^^^^
    > Get rid of the superfluous stuff. It's not even the correct syntax!
    >



    Sorry...my newsreader morphed my reply. Get rid of the " & exit" at the
    end of your command. I'd also change the command to read as follows:
    String dest = "/bin/tar cfz " + saveDir + nomZip + " " + saveDir + "*.csv";
    Sudsy, Dec 7, 2003
    #3
  4. charly

    charly Guest

    [SOLVED]Re: calling a bash script but cannot get out

    Thank you !

    In fact, the exit was useless and I should have thought a little harder
    before posting :

    I just had to to this :
    Process process = Runtime.getRuntime().exec(commande);
    process.waitFor(); -> It's a new thread : I've got to wait for him in
    this case :)

    thank you for your input though
    charly, Dec 7, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William Park

    (patch for Bash) GTK+2 + Bash

    William Park, Jul 11, 2005, in forum: XML
    Replies:
    3
    Views:
    2,293
    William Park
    Jul 14, 2005
  2. Gros Bedo
    Replies:
    2
    Views:
    1,287
    Piet van Oostrum
    Jul 10, 2008
  3. Gros Bedo
    Replies:
    1
    Views:
    660
    Piet van Oostrum
    Jul 10, 2008
  4. norseman
    Replies:
    0
    Views:
    560
    norseman
    Jul 10, 2008
  5. Dreamcat Four
    Replies:
    9
    Views:
    209
    Dreamcat Four
    Nov 19, 2010
Loading...

Share This Page