- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
目前,我正在使用 Mininet-Wifi 进行实验.它的 CLI 是 Python 的 Cmd 模块,这就是我能够获得有关模拟网络环境的准确信息的方式。模拟器在 Ubuntu 14.04 或更高版本上作为自己的进程作为 sudo python 运行。
这个网络的 Remote 是POX .这一次,只有一个脚本在运行;一切都是通过预设命令自动完成的——不再需要人工干预。我想做的是:POX 进程需要将命令注入(inject) Mininet 的进程并检索该命令的执行结果。这是因为 POX 的逻辑必须通过 Mininet 不断查询网络状态才能做出决策。做出决定后,POX 必须再次向 Mininet 进程注入(inject)命令以更改网络状态。
附录:目前,我只能在运行 sudo python a_mininet_script 时访问由 Mininet 生成的主机,这要归功于名为 m 的实用程序函数。产生主机后,Mininet 进入其 CLI 功能,这是我想与之通信但不能的。这是 Mininet 的 m 函数。
#!/bin/bash
# Attach to a Mininet host and run a command
if [ -z $1 ]; then
echo "usage: $0 host cmd [args...]"
exit 1
else
host=$1
fi
pid=`ps ax | grep "mininet:$host$" | grep bash | grep -v mnexec | awk '{print $1};'`
if echo $pid | grep -q ' '; then
echo "Error: found multiple mininet:$host processes"
exit 2
fi
if [ "$pid" == "" ]; then
echo "Could not find Mininet host $host"
exit 3
fi
if [ -z $2 ]; then
cmd='bash'
else
shift
cmd=$*
fi
cgroup=/sys/fs/cgroup/cpu/$host
if [ -d "$cgroup" ]; then
cg="-g $host"
fi
# Check whether host should be running in a chroot dir
rootdir="/var/run/mn/$host/root"
if [ -d $rootdir -a -x $rootdir/bin/bash ]; then
cmd="'cd `pwd`; exec $cmd'"
cmd="chroot $rootdir /bin/bash -c $cmd"
fi
cmd="exec sudo mnexec $cg -a $pid $cmd"
eval $cmd
例如,要从任何终端而不是 POX 脚本访问 h1 的终端,我会这样调用它:
sh m h1 ifconfig
但是要从子进程调用它,它将是:
p = subprocess.Popen('echo my passwd | sudo -kS sh m h1 ifconfig', shell = True)
重复我的问题,我想从 POX Controller 与 Mininet 进程的 CLI 通信,而不仅仅是生成的主机。
最佳答案
我猜你想实现类似 netstat -oan | 的功能findstr 80(这是在windows上找80端口),这是把netstat -oan的输出传递给命令findstr的管道命令。
然后python代码是这样的:
import subprocess
p1 = subprocess.Popen('netstat -oan', stdout=subprocess.PIPE, shell=True)
p2 = subprocess.Popen('findstr 80', stdin=p1.stdout, stdout=subprocess.PIPE, shell=True)
pipeline_output = p2.communicate()[0]
print pipeline_output
然后,p1 进程的输出将传递给 p2 进程,仅供引用。
关于python - 如何将 Python 的 cmd 类的输入/输出传输到另一个 Python 进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37560719/
我正在尝试制作一个命令行界面程序,它可以从用户输入中获取代码行并使用 execlp 执行它们。 我想知道是否有更好的方法来编写我的代码。 execlp(cmd[0], cmd[0], cmd[1] c
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我使用此脚本查找当前文件夹及其 .bat 文件: for /f %%i in ("%0") do set curpath=%%~dpi echo %curpath% 如果路径包含空格,它无法正常工作
在 Windows 的命令提示符处,我可以通过键入 echo 来回显响铃字符,然后按住 Ctrl+G 生成 echo ^G,运行时会发出铃声。 当我实际用键盘输入 echo ^G 时,它只会在屏幕上打
这是我执行的命令: >cmd /k >echo 1 1 >echo 2 2 >echo 3 3 >exit /b >cmd /c "doskey /history" echo 1 echo 2 ech
我需要编写一个命令来更改当前目录并打印包含在一些标签中的 NEW 目录。我以为 cd SOMEPATH & echo wkd%cd%wkd会这样做,但有一个问题。 这是一些示例输入和输出 C:\Use
我正在尝试从“调用 ppm 查询断言”中捕获 stoutput,如果它等于“ * 没有安装匹配 'assert' ** 的软件包”或更好但包含字符串“无软件包”做“某事” “.. 正在安装软件包。任何
似乎一个cmd脚本包含: prog1 prog2 与...相同 call prog1 call prog2 使用CALL命令有什么意义? 最佳答案 当需要调用另一个批处理程序(cmd脚本)时,应使用c
我要打电话 cmd /c "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" mysolution.sln /b
在 Windows 上,可以轻松以管理员身份运行 cmd 应用程序: Right click on cmd icon >> run as administrator` 但我想以管理员身份使用 PhpS
我目前正在使用 Python 的 cmd 模块创建一个基于命令的游戏。 在某个时刻,我的 cmd.Cmd 对象会被嵌套。如果我说我正在运行命令提示符 A,那么在某个时刻,会在 A 内创建一个新的提示符
我正在尝试构建一个 cli 框架,其中需要动态添加命令。我想要实现的是 - 我将有一个继承自 cmd.Cmd 的最小类,稍后我将在单独的类中编写命令并将这些命令与主类一起加载。 以下是我尝试过的,但在
以下命令有什么区别: start %comspec% /c script.cmd start cmd /C script.cmd 我需要 script.cmd 的 cmd 窗口在 script.cmd
我正在尝试将一个长而复杂的 Windows 批处理文件转换为 Python。 除了细微的问题外一切正常,我怀疑这与引用有关,但不太清楚。 在批处理文件中,这工作正常: Reg.exe add "HKC
我想为 ffplay 或 ffmpeg 传递多个标题,它说我需要用 CRLF 拆分。在 linux 上我可以使用 \或 $'\r\n'但是 window 怎么样? SET CRLF=^ ffplay
我是 3D 软件 Blender 的用户。 我正在尝试在 CMD 中运行,因为 Blender 提供了 CLI 控制。 下面的代码工作正常。 blender -b "my.blend" ^ --pyt
我有一个包含版本资源的文件,其中填充了文件版本/产品版本字段。我需要通过 BAT 文件检索产品版本。例如,我在 bat 文件的输出中有 ProductVersion 1.0.1 的文件我不想有字符串“
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。 Improve this
我可以运行 forfiles 命令与cmd /c ,正如预期的那样 C:\>forfiles/c "cmd/c ping/a" 必须指定 IP 地址。 但是,如果我删除 cmd /c ,它不再识别任何
我有一个函数,它可以获取所有 USB 连接设备的信息。 connected_devices = :os.cmd('usb-devices | grep -A 1 Product=') 当我使用 :os
我是一名优秀的程序员,十分优秀!