1

I am currently writing a program to help me with some database administration. It's supposed to execute commands in MariaDB. I thought since this is a CLI application I can just do that with os.system, but I'm having problems doing so. So lets say I have the following code

import os

os.system('mysql --user=%s --password=%s' %(user, password)
os.system('USE database;')

This code logs me into MariaDB, but it does not execute the second command to choose the database. Is this possible with os.system, and if not, what are my alternatives? Thanks.

Edit: I tried using subprocess instead, which gives me another problem: It immediately exits MariaDB after logging in.

Brian
  • 117
  • 1
  • 13

1 Answers1

0

I recomand you to use Subprocess instead of os python module, using Popen

try to check this link out : Calling an external command in Python

Community
  • 1
  • 1
Hilmi Reda
  • 94
  • 7
  • Using subprocess gives me a different error, it immediately stops MariaDB after logging in. – Brian Mar 30 '17 at 17:03