Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Shell在pyqt5gui的子进程中使用更复杂的nmap命令时不断重新启动_Python_Python 3.x_Nmap - Fatal编程技术网

Python Shell在pyqt5gui的子进程中使用更复杂的nmap命令时不断重新启动

Python Shell在pyqt5gui的子进程中使用更复杂的nmap命令时不断重新启动,python,python-3.x,nmap,Python,Python 3.x,Nmap,我正在开发Raspberry Pi 3,目前,我正在尝试在PyQt5中为一些nmap命令创建GUI 或多或少,我从一个列表中获取输入,编辑subent,然后使用各种命令,它就不起作用了。我正在使用子流程来实现这一点,因为我只需要终端的输出 nmap库中的一些命令工作得很好,没有问题,我成功地获取了结果,但对于其他命令,结果仍在继续 我尝试打印此命令的结果: sudo nmap-p 80443 192.168.1.1/24-oG- 我使用的方法是: def nmapHttScan(self):

我正在开发Raspberry Pi 3,目前,我正在尝试在PyQt5中为一些
nmap
命令创建GUI

或多或少,我从一个列表中获取输入,编辑subent,然后使用各种命令,它就不起作用了。我正在使用
子流程
来实现这一点,因为我只需要终端的输出

nmap库中的一些命令工作得很好,没有问题,我成功地获取了结果,但对于其他命令,结果仍在继续

我尝试打印此命令的结果:

sudo nmap-p 80443 192.168.1.1/24-oG-

我使用的方法是:

def nmapHttScan(self):
    subnet = str(self.leNmap.text())
    result = ' '
    res= subprocess.Popen(['sudo','nmap','-p 80,443',''+subnet,'-oG -'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,encoding = 'utf-8')
     while True:
        output=res.stdout.readline()
        if output =='' and res.poll() is not None:
            break;
        if output:
            print('output',output.strip())
        rc=res.poll()
     print(str(rc))
每次我按下GUI中的按钮,以便看到结果时,shell就会重新启动,我真的不知道该怎么办

我想我可能使用了
process.poll()
方法,但我已经在这个问题上工作了大约4-5天,我已经到处搜索了。所以,拜托,如果你有任何想法,我愿意尝试任何东西


谢谢你,祝你今天愉快

你所做的事情似乎太复杂了。这是一个更好的方法:

import sys
import os
from PyQt5.Qt import QApplication, QClipboard
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QWidget, QPlainTextEdit, QPushButton
from PyQt5.QtCore import QSize

class ExampleWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(640, 440))    
        self.setWindowTitle("PyQt5 NMAP example") 

        # Add text field
        self.b = QPlainTextEdit(self)
        self.b.move(10,10)
        self.b.resize(600,300)

        # Create a button in the window
        self.button = QPushButton('Show text', self)
        self.button.move(120,380)

        # connect button to function on_click
        self.button.clicked.connect(self.functionnmap)

    def functionnmap(self):
        p = os.popen('sudo nmap -p 80,443 192.168.1.1/24 -oG -')
        output = p.read()
        self.b.insertPlainText(output)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWin = ExampleWindow()
    mainWin.show()
    sys.exit( app.exec_() )

它很好用。是的,我确实把整个问题复杂化了。我在其他命令上使用了popen.run(),它工作得很好,但在这个命令上有问题。谢谢。我认为这个答案可以通过添加对您提供的代码的简短解释来改进,因为这可能对未来的读者有所帮助。@ChiricaGabriel在命令运行时您是否尝试过调整窗口大小?我把冰箱冷冻起来GUI@eyllanesc如果你说的是niros代码中的窗口,我在调整窗口大小方面没有任何问题,但即使你的函数在我的pi上解决了我的代码问题,我仍然有一个问题,不知怎的,它停止了,因为一些关于交易的事情,所以我仍然在研究这个问题。目前,我正试图看看我是否有一些东西是由于我的gui和测试的一切。