[英]Shell doesn't respond first input character after executing my program which executes shell command
我有一个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);
}
rsh上的“ ip link show bond0”输出包含转义字符,导致控制台输入问题。
我这样改变了命令。 有效。
char * cmdline =“ / sbin / ip链接显示bond0> / dev / null 2> / dev / null && inf = bond0 || inf = eth0;”
我对变量getpeerip做了同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.