Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:34:07+00:00 2026-06-17T04:34:07+00:00

I want to invoke mysqldump from a Spring based webapp and write the output

  • 0

I want to invoke mysqldump from a Spring based webapp and write the output to a file. I want to be able to provide a download link to the user to the file created on the server.

I tried running the following:

Runtime.getRuntime().exec("/usr/bin/mysqldump -u <username> -p<password> <db_name> >" + fileName);
Runtime.getRuntime().exec("mysqldump -u <username> -p<password> db_name >" + fileName);

I tried the following values of fileName.

fileName = "mysql.sql";
fileName = "/tmp/mysql.sql";
fileName = servletContext.getRealPath("") + "/mysql.sql";

But the command is not successful. process.exitValue() returns an error code of 2 or 6.

  ProcessBuilder pb = new ProcessBuilder("/usr/bin/mysqldump", " -u ", "<username>", " -p<password>", "<db_name>", " > ", fileName);
  pb.redirectErrorStream(true); // equivalent of 2>&1
  Process p = pb.start();
  p.waitFor();

This does not help as well.

Can someone tell me what is the best way to run such a command from the webapp? Where should the output file be created?
What is wrong with the commands above?

I need to be able to run this on different systems (Linux, Windows). The webapp runs on either system. I can abstract out the mysqldump path in a properties file if the need arises. But how do I make this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:34:08+00:00Added an answer on June 17, 2026 at 4:34 am

    This is probably not a very good idea. The servlet probably needs a very permissive security environment for this to work at all. If you do a search you will find lots of people having problems with this.

    Even if it works the runtime exec might block for some reason and the servlet would timeout, I don’t know the ramifications of that, but they don’t sound good to me.

    We had a similar problem where I worked a couple of years ago and wrote a simple multithreaded server that would queue up requests, and run them when it got a chance and handled things like hangs, crashes and restarts. It ran as a jsvc daemon. The servlet sent it a message over a socket.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to invoke one application from another application. My Java file code: Intent
I want to invoke a mssql procedure via php $link = mssql_connect($this->serverName, $this->user, $this->password);
I want to invoke a method of an object from user defined class for
I want to invoke a masterPage's method from a inner user-control (user control inside
I want to invoke my rake task from console. Is it doable? if yes,
I have a project, in which I want to invoke another Jar file in
This is my javascript method in .aspx file. I want to invoke this method
I have a program which i want to invoke from windows service. xsftp.StartInfo =
From a managed c++ function I want to invoke an unmanaged function that expects
I want to write a localStorage item to a text file and want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.