2017-04-05 66 views
0

我要開POPEN一個腳本,用sysargv的說法是這樣的:的Python POPEN sysargv

import subprocess 

Script = '/home/Network_Monitor_Device/Scripts/Traceroute.py 192.168.76.1' 

p = subprocess.Popen(['python','-u',Script], stdout = subprocess.PIPE, stderr=subprocess.STDOUT) 

out = p.stdout.readline() 

print out 

Traceroute.py

import os 
import sys 
import subprocess 

subprocess.check_output("traceroute " + str(sys.argv[1]), shell=True) 

我得到這個錯誤:

python: can't open file '/home/Network_Monitor_Device/Scripts/Traceroute.py 192.168.76.1': [Errno 2] No such file or directory

回答

0

它期待一個列表。嘗試:

p = subprocess.Popen(['python','-u', '/home/Network_Monitor_Device/Scripts/Traceroute.py', '192.168.76.1'], stdout = subprocess.PIPE, stderr=subprocess.STDOUT) 
+0

當我嘗試,我得到這個錯誤:'TypeError:execv()arg 2只能包含字符串' – Manariba

+0

這樣做!謝謝! – Manariba