擅长:python、mysql、java
<p><code>></code>是shell重定向运算符。在shell中运行该命令,或者(更好)作为<a href="https://stackoverflow.com/a/28450855/4279">@Padraic Cunningham suggested</a>在Python中模拟它:</p>
<pre><code>#!/usr/bin/env python
import subprocess
args = r"C:\DO\bin\Config.exe ChCfg7 LFE -b1152000".split()
args += [r'C:\DO\PCM\%d.wav' % i for i in range(1, 7)]
args += [" ModeBCast", r"-oC:\DO\OUT\outfile"]
with open(r"C:\DO\OUT\log.txt", "wb", 0) as output_file:
subprocess.check_call(args, stdout=output_file)
</code></pre>
<p>该代码对Windows路径使用原始字符串文本,以避免转义反斜杠。在</p>
<p>在Windows上使用<code>shell=True</code>通常没有意义,除非您想运行一个内置命令,如<code>dir</code>。如果<code>args</code>不是使用来自外部源的输入构造的,那么<a href="https://docs.python.org/dev/library/subprocess.html#security-considerations" rel="nofollow noreferrer">security considerations</a>do<em>not</em>应用。<code>shell=True</code>启动附加进程(<code>%COMSPEC%</code>),它改变<a href="https://stackoverflow.com/q/24789749/4279">how the executable is searched</a>,并且改变{a4}-除非必要,否则不要使用<code>shell=True</code>。在</p>