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

2024-05-13 07:44:54 发布

您现在位置: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

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


Tags: inpyimporttrueliblineshellcall