如何逐行调用文件以使用python在文件中的每一行上传递命令?

时间:2014-11-24 19:39:47

标签: python

import subprocess
import sys

f = open('IPList.txt')
for line in f:
    subprocess.call("nslookup", line, shell=True)
    #print (line)
f.close()

以上程序不起作用。低于错误:

=============================================== =======================

PS C:\Python34> .\Python testnslookup.py
Traceback (most recent call last):
File "testnslookup.py", line 7, in <module>
  subprocess.call("nslookup", line, shell=True)
File "C:\Python34\lib\subprocess.py", line 537, in call
  with Popen(*popenargs, **kwargs) as p:
File "C:\Python34\lib\subprocess.py", line 767, in __init__
  raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

=============================================== ========================

1 个答案:

答案 0 :(得分:2)

尝试将所有call非关键字参数放在列表中。

subprocess.call(["nslookup", line], shell=True)