我试图在python中处理tcpdump输出.
我需要的是运行tcpdump(捕获数据包并给我信息)并读取输出并处理它.
问题是tcpdump一直在运行,我需要在输出后立即读取数据包信息并继续执行.
我试着查看python的子进程并尝试使用popen调用tcpdump并管道stdout但它似乎没有用.
关于如何进行此操作的任何指示.
import subprocess
def redirect():
tcpdump = subprocess.Popen("sudo tcpdump...", stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
while True:
s = tcpdump.stdout.readline()
# do domething with s
redirect()
Run Code Online (Sandbox Code Playgroud) 我看到很多关于如何将布尔值绑定到单选按钮的帖子.但我的情况是我需要将它绑定到单选按钮并从用户读取选择.
这是不应该选择的选项.
如果我将它绑定到布尔值,由于布尔值不为null,它显示在单选按钮中选择的默认值.
如果我使用可空布尔值,我在尝试使用转换器时仍然默认为false.
我不能在xaml中使用单向模式,因为我需要检查是否使用有界变量进行单选按钮选择.
关于如何实现这个蚂蚁指针?
假设我的目标是以以下形式创建一个 xml:
<main>
<elements>
<element name="elem1"><temp/>
</element>
<element name="elem2"><temp/>
</element>
</elements>
</main>
Run Code Online (Sandbox Code Playgroud)
我有以下代码:
ptree pt;
pt.put("main","");
ptree temp1;
temp1.put("element","");
temp1.put("element.<xmlattr>.name","elem1");
temp1.put("element.temp");
ptree temp2;
temp2.put("element","");
temp2.put("element.<xmlattr>.name","elem2");
temp2.put("element.temp");
//temp1 represents the 1st <element>...</element>
//temp2 represents the 1st <element>...</element>
//Add temp1 and temp2 to <main> under <elements>
Run Code Online (Sandbox Code Playgroud)
我认为以下内容会起作用:
pt.add_child("main.elements",temp1);
pt.add_child("main.elements",temp2);
Run Code Online (Sandbox Code Playgroud)
但是,这会生成以下 xml:
<main>
<elements>
<element name="elem1"><temp/>
</element>
</elements>
<elements>
<element name="elem2"><temp/>
</element>
<elements>
</main>
Run Code Online (Sandbox Code Playgroud)
通过将我的 temp1 设置为以下形式,我能够获得所需的 xml 文件:
temp1.put("<xmlattr>.name","elem1");
temp1.put("temp","");
temp2.put("<xmlattr>.name","elem2");
temp2.put("temp","");
pt.add_child("main.elements.element",temp1);
pt.add_child("main.elements.element",temp2);
Run Code Online (Sandbox Code Playgroud)
有没有办法可以使用我的初始 temp1 和 temp2 节点来获得所需的 xml 结构?