如何将命令行字符串转换为数组?

时间:2015-11-03 20:04:04

标签: python python-2.7

我在一个字符串变量中有一个命令行(这不是我的程序参数,我把它放在其他地方):

cmd_line = "app.exe --a value -b \"this is a quoted string\"";

如何将此命令行转换为数组?

res = ["app.exe", "--a", "value", "-b", "this is a quoted string"]

有一个winapi函数CommandLineToArgvW。 Python中有一个等价的东西吗?

1 个答案:

答案 0 :(得分:1)

shlex.split()正是这样做的:https://docs.python.org/2/library/shlex.html

相关问题