I am new to Socket Programming in Python. I have written the following code in Python 3.7:
trialSocketList.py
import subprocess
import sys
HOST = sys.argv[1]
PORT = sys.argv[2]
command = "tnc " + HOST + " -PORT "
print(command)
subprocess.call(command + PORT)
I am passing the following in the Windows CMD:
python trialSocketList.py "127.0.0.1" 445
But I am having the following error while executing the above code:
tnc 127.0.0.1 -PORT
Traceback (most recent call last):
File "trialSocketList.py", line 14, in <module>
subprocess.call(command + PORT)
File "C:\Python37\lib\subprocess.py", line 323, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Python37\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Python37\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
When I try netstat -an
instead of the command tnc 127.0.0.1 -PORT
in the same code, the code functions perfectly. I have written the above few lines of code after reading this API.
*I can run tnc
command if I hit it directly in Windows cmd.
Am I missing something here? Or is there any other better way of doing this? If so, then please help me understand the issue here.
Thanks in advance.