【发布时间】:2011-12-28 01:35:59
【问题描述】:
我正在尝试从 c 执行 bash 命令并检索并显示结果。 我已经尝试过使用系统,但它不起作用。 我的代码如下:
char command[200];
sprintf(command,"lsof -iTCP:%d | cut -d\"\" -f1 | tail -1",port);
printf("Port %d is open\n and is listened by %s",port,system(command));
请帮忙。我需要这个。
【问题讨论】:
-
考虑重新表述这个问题,以便清楚您实际上并不是在尝试启动 bash 命令,而是实际上想要找到侦听特定端口的进程(来自 c++)跨度>
-
我正在尝试运行 bash 命令。找不到正在侦听端口的服务
-
好的,谢谢你解决这个问题