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 7872807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:19:19+00:00 2026-06-03T02:19:19+00:00

I want to call a subprocess to backup mysql database. A command line which

  • 0

I want to call a subprocess to backup mysql database.
A command line which ran fine in the terminal (and created a file named mydatabase.sql) is:

    mysqldump -uroot -ppassword --add-drop-database --database mydatabase > mydatabase.sql

Now the code to be ran by python to call a subprocess:

    args = shlex.split('mysqldump -uroot -ppassword --add-drop-database --database mydatabase > mydatabase.sql')
    subprocess.check_call(args)

The exeption is raised (no file created):

    Traceback (most recent call last):
      File "<pyshell#29>", line 1, in <module>
        subprocess.check_call(args)
      File "/usr/lib/python3.2/subprocess.py", line 485, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['mysqldump', >'-uroot', '-ppassword', '--add-drop-database', '--database', >'mydatabase', '>', 'mydatabase.sql']' returned non-zero exit status 2

I have tried different ways, but they still don’t work:

    args = shlex.split('/opt/lampp/bin/mysqldump -uroot -ppassword --add-drop-database --database mydatabase > mydatabase.sql')
    subprocess.check_call(args)

or

    args = shlex.split('/opt/lampp/bin/mysqldump -uroot -ppassword --add-drop-database --database mydatabase > mydatabase.sql')
    subprocess.Popen(args)

I also tried with shell=True or or shell=False. In both cases, they still don’t work.

I have read the docs, google for the answer for my problem, but I haven’t got a clue how to show my problem. stackoverflow is probably my last hope.

  • 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-03T02:19:20+00:00Added an answer on June 3, 2026 at 2:19 am

    the problem here is the way you’re redirecting the output.

    • if you pass the command as a list of arguments, then ">" will always be interpreted as a literal >, no matter if you use shell=True or shell=False
    • if you pass the command as a single string, then it hould work, but only if you have shell=True.
    • the best way do do what you want would be to redirect the output to a file directly from python:

      args = shlex.split('/opt/lampp/bin/mysqldump -uroot -ppassword --add-drop-database --database mydatabase')
      output = open("mydatabase.sql", "w")
      subprocess.Popen(args, stdout=output)
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside a subprocess call, I want to use shell=True so that it does globbing
I want to call a python script, script1.py , which takes a regex string
I have a function which I call a progarm, with some args and want
I want to run a command in pythong , using the subprocess module, and
I want to do subprocess.call, and get the output of the call into a
Im using subprocess.call to execute a bat file. subprocess.call is waiting for the bat
Suppose I want to call a subprocess from within my program, and I want
In my code I have a line similar to this: rval = subprocess.call([mkdir,directoryName], shell=True)
I want to call a new view controller and remove the current view controller
I want to call another intent from ArrayAdapter class using startActivityForResult but i cann't

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.