Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can execute Ubuntu commands in Python by using the subprocess module. Here's an example:

import subprocess

result = subprocess.run(['ls', '-l'], stdout=subprocess.PIPE)
print(result.stdout.decode('utf-8'))

In this example, the subprocess.run() function is used to execute the Ubuntu command ls -l. The stdout=subprocess.PIPE parameter indicates that the output of the command should be captured and returned as a byte string. Finally, we decode the output using the decode() method to convert the bytes to a human-readable string.

You can replace ls -l with any Ubuntu command you want to execute in Python.