【发布时间】:2019-09-01 06:55:15
【问题描述】:
我是 Python 套接字编程的新手。我在 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)
我在 Windows CMD 中传递以下内容:
python trialSocketList.py "127.0.0.1" 445
但我在执行上述代码时遇到以下错误:
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
当我在同一代码中尝试 netstat -an 而不是命令 tnc 127.0.0.1 -PORT 时,代码运行良好。看了this API,我写了上面几行代码。
*如果我直接在 Windows cmd 中点击tnc 命令,我可以运行它。
我在这里遗漏了什么吗?或者还有其他更好的方法吗?如果是这样,请帮助我理解这里的问题。
提前致谢。
【问题讨论】:
标签: python subprocess python-sockets