【发布时间】:2017-11-30 10:37:16
【问题描述】:
import shlex
import os
os.environ['SERVER_SOFTWARE'] = 'Dev'
import subprocess, socket, time, struct
def execute_command(cmd):
f = open(log.name, "w")
try:
subprocess.Popen(cmd, 0, f, f)
except WindowsError:
cmd[0] = cmd[0] + ".com"
subprocess.Popen(cmd, 0, f, f) #work-around
rc = process.wait()
if rc != 0:
print("Error: failed to execute command:", cmd)
print(error)
return result
def main():
execute_command(["tree", "C:\\"], "treelog.txt")
return
【问题讨论】:
-
def_main():似乎是一个错字。你的意思可能是def main():如果你要编程,你需要提高对细节的关注。 -
另外,请正确格式化您的代码。这是不可读的。
-
你能展示你只将一个参数传递给
execute_command的版本吗?传递两个参数是一个错误是显而易见的。 -
我只改了def main(),像这样:excecute_command(["tree"], "treelog.txt") return
标签: python