擅长:python、mysql、java
<p>试试这个(在windows上):</p>
<pre><code>import subprocess
file_name = "test.txt"
sp = subprocess.Popen(["cmd", "/c", 'dir', '/s', '/p', file_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = sp.communicate()
output = output[1].decode()
if file_name in output:
print("yes")
else:
print("no")
</code></pre>
<p>在Linux上,替换对子进程的调用,如下所示:</p>
^{pr2}$
<p>我想钥匙在:<code>stdout=subprocess.PIPE, stderr=subprocess.PIPE</code></p>