【问题标题】:Bash command inPython not outputting anything to terminalPython中的Bash命令没有向终端输出任何内容
【发布时间】:2021-06-08 16:53:39
【问题描述】:

我正在尝试运行 bash 命令来启动 Nikto 并在终端中显示输出,但是程序没有返回任何内容。任何帮助将不胜感激,谢谢。

在输入到python程序之前,该命令在终端中运行良好

import subprocess
import os

def bash(command):
    return subprocess.check_output(['bash', '-c', command])

def niktoScan():
    res = bash('nikto -Display 1234EP -o report.html -Format htm -Tuning 123bde -host 127.0.0.1').splitlines()
    print(res)

【问题讨论】:

    标签: python bash python-2.7 subprocess


    【解决方案1】:

    到目前为止,您只定义了函数,但还没有调用它们。如果我理解正确,您可以在末尾添加niktoScan()

    import subprocess
    import os
    
    def bash(command):
        return subprocess.check_output(['bash', '-c', command])
    
    def niktoScan():
        res = bash('nikto -Display 1234EP -o report.html -Format htm -Tuning 123bde -host 127.0.0.1').splitlines()
        print(res)
    
    niktoScan()
    

    【讨论】:

    • 啊,对不起,我忘了把它添加到我的代码末尾。程序仍然只是等待并且不返回任何输出
    猜你喜欢
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    相关资源
    最近更新 更多