【发布时间】:2016-05-06 04:36:42
【问题描述】:
我正在尝试创建一个返回输出的函数,因为命令将写入 Windows 或 Linux 的命令行?
示例:
def cmd_simulator(commands):
#some code
cmd_simulator("date")
- Thu Jan 28 12:18:05 EST 2016
或 Windows:
cmd_simulator("date")
- The current date is: Thu 01/28/2016
- Enter the new date: (mm-dd-yy)
【问题讨论】:
-
您想将您的命令委托给控制台外壳吗?
-
subprocess.check_output可能对你有用。 -
cmd_simulator=lambda cmd:os.popen(cmd).read();print cmd_simulator("date")
标签: python shell command-line