【发布时间】:2017-12-04 17:35:56
【问题描述】:
我有一个包含多个 pydev 模块程序的项目。没有一个模块相互链接或导入到其他模块中。都是独立的模块。 我看到两个程序存在问题,即:“CmdOnRemoteServer”和“ipaddress”
当我执行程序“CmdOnRemoteServer”程序时,控制台打印先前/旧程序“ipaddress”的输出,然后跳转到当前程序“CmdOnRemoteServer”并打印输出。 我可以通过将程序调试并在两个程序中设置断点来找到这种行为。
在 Preferences>>Run/Debug>>Launching 中,选择的选项是“Launch the selected resource or active editor”和“If not launchable>>Launch the previous launch the application”
我在“CmdOnRemoteServer”中添加了 'if ____name____ == "____main____":' 代码,但这也没有帮助。 我附上了显示主线程中列出的两个程序的调试屏幕截图。
有人可以帮我解决这个问题吗?
根据要求,将代码添加到问题中:
if __name__ == "__main__":
remoteServer=winrm.Session("IDCQEAM190.amdom009.lab", auth = ("Administrator", "Control123"))
remoteCMD = remoteServer.run_cmd("ipconfig", ["/all"])
myfile = open(r"C:\Users\pshastri\Desktop\remoteServer.txt", "w")
myfile.write(remoteCMD.std_out)
myfile.close()
myfile = open(r"C:\Users\pshastri\Desktop\remoteServer.txt", "r")
ipPatt = "IPv4 Address[\.\s]{1,}:\s[\d+\.]{1,}"
hostPatt = "Host Name [\.\s]{1,}: [A-Za-z0-9]+"
domPatt = "Primary Dns Suffix [\.\s]{1,}: [A-Za-z0-9]+\.[A-Za-z0-9]+"
myfile.seek(0)
ipReg = re.findall(ipPatt, myfile.read())
myfile.seek(0)
hostReg = re.findall(hostPatt, myfile.read())
myfile.seek(0)
domReg = re.findall(domPatt, myfile.read())
print "".join(ipReg), "\n", "".join(hostReg), "\n", "".join(domReg)
【问题讨论】:
-
您是否准确添加了
if ____name____ == "____main____":?因为如果是这样,这是无效的 python 语法,你应该输入if __name__ == "__main__":。另外,您可以为 CmdOnRemoteServer 添加代码吗? -
不是因为这里的文本格式。如果我输入了不正确的语法,我会遇到一些编译错误。将代码添加到主要问题。