I'm trying to redirect the output of an Nmap scan to a text file using Python.
Here's my code:
outputName = raw_input("What is the output file name?") fname = outputName with open(fname, 'w') as fout: fout.write('') command = raw_input("Please enter an Nmap command with an IP address.") args = shlex.split(command) proc = subprocess.Popen(args,stdout=fname) The error:
Traceback (most recent call last): File "mod2hw4.py", line 17, in <module> proc = subprocess.Popen(args,stdout=fname) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 701, in __init__ errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1127, in _get_handles c2pwrite = stdout.fileno() AttributeError: 'str' object has no attribute 'fileno'