Чтобы выполнить команду и получить вывод в Python, вы можете использовать несколько методов. Вот несколько примеров:
-
Использование модуля
subprocess
:import subprocess command = "your_command_here" output = subprocess.check_output(command, shell=True).decode("utf-8") print(output)
-
Использование модуля
os
:import os command = "your_command_here" output = os.popen(command).read() print(output)
-
Использование модуля
sh
:import sh command = "your_command_here" output = sh.run(command, capture_output=True).stdout.decode("utf-8") print(output)
-
Использование модуля
multiprocessing
:import multiprocessing def execute_command(command): return subprocess.check_output(command, shell=True).decode("utf-8") command = "your_command_here" pool = multiprocessing.Pool(processes=1) output = pool.apply(execute_command, (command,)) print(output)
Эти методы позволяют выполнять команды и получать выходные данные в Python. Не забудьте заменить "your_command_here"
на фактическую команду, которую вы хотите выполнить.