xxxxxxxxxx
import subprocess
def get_command_output(command):
try:
# Execute the command and capture the output
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
# Decode the output (assuming it's encoded in UTF-8)
decoded_output = output.decode('utf-8')
# Return the decoded output
return decoded_output
except subprocess.CalledProcessError as e:
# Handle any errors that occurred during command execution
print(f"Error executing command: {e}")
return None
# Example usage:
output = get_command_output('ls -l')
print(output)
xxxxxxxxxx
import subprocess
py2output = subprocess.check_output(['python', 'py2.py', '-i', 'test.txt'])
print('py2 said:', py2output)
xxxxxxxxxx
Version info: NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://www.archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
LOGO=archlinux