2

I am having shell script whose output is output.zip.

i want to Run Shell script on server using browser and download output.zip.

Please suggest me how i can do this, which technology i should use.

4
  • you have java web app running on a server, and there is a zip file on that server, you don't want to download it via your java web-app, but via shellscript... can you give a reason, why not read the file in java and write response to client (browser)? Commented Apr 5, 2013 at 10:07
  • I think he wants to generate it using shell script and download it using web-app. Commented Apr 5, 2013 at 10:12
  • you are right @A4L I want to Run shell scripts from server and download output of the shell script Commented Apr 5, 2013 at 10:16
  • then have a look at @jakub.petr answer, you can alternatively provide download link to it after it is generated if you dont want to read it by yourself sream it to the client as jakub.petr suggests in his answer. Btw a better alternative to Runtime.getRuntime(...).exec is to use ProcessBuilder Commented Apr 5, 2013 at 10:20

1 Answer 1

1

Not sure about your server platform but I assume you have JAVA there and you can handle http request.

Create output file with this command:

Runtime.getRuntime().exec("sh test.sh");

The second part is to stream content of your file as response. Just set response header to

Content-Description: File Transfer 
Content-type: application/octet-stream
Content-Disposition: attachment; filename="YourFilename.zip"
Content-Transfer-Encoding: binary
Content-Length: LengthOfYourFileInBytes

and you can send your file content as body of the response.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.