Get the Output of System Command as a String in Python 发表于 2023-03-03 更新于 2024-08-22 分类于 Python 文章标准 暂无 Use os.popen(): output = os.popen('ls').read() The newer way (> Python 2.6) to do this is to use subprocess: output = subprocess.Popen('ls', stdout=subprocess.PIPE).stdout.read()