The commands module contains wrapper functions for os.popen() which take a system command as a string and return any output generated by the command and, optionally, the exit status.
The subprocess module provides more powerful facilities for spawning new processes and retrieving their results. Using the subprocess module is preferable to using the commands module.
The commands module has been removed in Python 3. Use the subprocess module instead.
import commands
output = commands.getoutput('ls')
print(output)
num = output.count('d')
print("Number: ", num)
Python
Vim
Doston Hamrakulov
Software Engineer, Web Developer, Freelancer
Enjoy open-source community