command_helper.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:petronia 作者: groboclown 项目源码 文件源码
def exec_cmd(bus, *cmd_line):
    """
    Executes an external process using the given arguments.  Note that the
    backslash (`\`) character must be escaped, because they are within a Python
    string, so a total of 2 backslashes to equal 1 real backslash.

    For example, to run a command prompt with fancy colors and start it in the
    root of the file system when you press <kbd>F1</kbd>, use:
'f1 => cmd cmd.exe /c start cmd.exe /E:ON /V:ON /T:17 /K cd \\'
```

:param bus:
:param cmd_line: The command-line string equivalent to run.
:return:
"""
# The cmd_line is a space-split set of arguments.  Because we're running a
# command line, and should allow all kinds of inputs, we'll join it back
# together.
full_cmd = " ".join(cmd_line)

# We won't use shlex, because, for Windows, splitting is just unnecessary.
print('CMD Running `' + full_cmd + '`')
# TODO look at making this a bus command, or at least a bus announcement.
proc = subprocess.Popen(full_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
bus.fire(event_ids.LOG__INFO, target_ids.LOGGER, {
    'message': '{0}: {1}'.format(proc.pid, full_cmd)
})

```

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号