How to return the previous command in Python?
In Python, the os.system() function can be used to execute system commands. To capture the output of the previous command and store it in a variable, you can use the $() or “ symbols.
Here is an example.
import os
# 执行命令并将输出存储到变量中
output = os.popen('上个命令').read()
# 打印输出
print(output)
Please note that the os.system() function returns the command’s return value after execution, instead of the output. If you only need the command’s output, it is better to use the os.popen() function.