Fedrik
Fedrik

Reputation: 133

How to execute a system command from a python file

I am using python and trying to execute a system command as below

code.py

import commands
import os

os.system('updatedb')

result:

sh-4.2$ python code.py
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'

So how to execute all the system commands like above from a python module ?

Upvotes: 0

Views: 432

Answers (1)

ckhan
ckhan

Reputation: 4791

This is almost certainly simply a permissions problem. If you can trust your script to run as root:

$ sudo python code.py

Upvotes: 3

Related Questions