calling a bash script but cannot get out

C

charly

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 :)
 
S

Sudsy

charly said:
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!
 
S

Sudsy

Sudsy said:
^^^^^^^
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";
 
C

charly

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top