我有一个C程序试图使用(rsh)命令执行远程命令执行。它试图提取IP信息和执行命令。执行我的程序后,我在shell提示符下登陆。我的C程序成功存在(Strace和ps -ef确认相同)。
现在在shell中键入任何字符时,shell不响应。它适用于下一键输入。
我正在使用bash shell
C程序看起来像这样。
char *cmdline = "/sbin/ip link show bond0 2>/dev/null && inf=bond0 || inf=eth0;"
"/sbin/ip -6 addr show $inf scope link | /bin/awk '/inet6/ { print \$2 }'";
char *getpeerip = "/usr/bin/rsh $(/sbin/ifconfig eth1 | /bin/awk '/inet/ { print \$2 }'"
"| /bin/awk -F: '{ print \$2 }'"
"| /bin/awk -F. '{ printf \"%%s.%%s.%%s.%d\", \$1, \$2, \$3 }') "
"\"/sbin/ip link show bond0 2>/dev/null && inf=bond0 || inf=eth0;"
"/sbin/ip -6 addr show $inf scope link | /bin/awk '/inet6/ { print \\$2 }'\"";
char lnkbuf[300];
cpid = p_getset->local_addr_ids[i].entity_instance;
if (cpid == getThisCPNum()) {
cmd_file = popen(cmdline, "r");
} else {
sprintf(lnkbuf, getpeerip, 1+getPeerCPSlot());
cmd_file = popen(lnkbuf, "r");
}
if (cmd_file != NULL) {
fgets(lnkbuf, 100, cmd_file);
fclose(cmd_file);
}
答案 0 :(得分:1)
“ip link show bond0”输出rsh包含转义字符导致控制台输入问题。
我改变了这样的命令。它奏效了。
char * cmdline =“/ sbin / ip link show bond0> / dev / null 2> / dev / null&& inf = bond0 || inf = eth0;”
我为变量getpeerip做了同样的事情。