-1

我需要执行以下命令(以及其他几个类似命令)来收集 Windows 操作系统事件日志:

' wmic nteventlog where filename="appevent" call BackupEventLog C:\appevent.evt '

该命令通过 cmd 提示符成功执行。并收集文件 C:\appevent.evt 但是当我使用 Python os.systemos.popen执行它时会重新运行错误。

.bat此外,如果我使用上述命令创建文件并执行.bat使用os.system它可以正常工作,

当我使用 cmd 执行时出了什么问题os.system?以及如何使用 Python 执行命令?

4

1 回答 1

2

它是由于\a字符串中的。\通过替换它来转义字符串中的\\

' wmic nteventlog where filename="appevent" call BackupEventLog C:\\appevent.evt '

或使用原始字符串:

r' wmic nteventlog where filename="appevent" call BackupEventLog C:\appevent.evt '
于 2011-06-24T02:47:01.230 回答