2017-06-27 62 views
-6
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 
+1

'def_main():'似乎是一個錯字。你可能是指'def main():'如果你要編程,你需要提高對細節的關注。 –

+1

另外,請正確格式化您的代碼。這是不可讀的。 –

+0

您可以顯示只傳遞一個參數到'execute_command'的版本嗎?通過兩個參數是一個錯誤是顯而易見的。 – mkrieger1

回答

0

的錯誤信息是非常明確的,而且我驚訝你需要任何的解釋:你定義的函數execute_command(cmd)接受單個參數( cmd),然後用兩個參數調用它。

在你的代碼中還存在其他一些問題,但是因爲你沒有打擾過格式化你的代碼和寫一個真正的問題(複製/粘貼錯誤信息的標題,因爲標題不算作「一個真正的問題「),我也不打擾他們。

相關問題