在 Windows 上将命令通过管道传输到缓冲区
我有以下适用于 Linux 的代码:
char pi[512];
FILE *fp1;
char pingStr[250];
sprintf(pingStr, "ping %s", info->server);
fp1 = popen(pingStr,"r");
fgets(pi,512,fp1);
fgets(pi,512,fp1);
Send("%s\r\n",pi); //my function
fclose(fp1);
Windows 上有等效的代码吗?因为我似乎无法让它发挥作用。
我想做的是将 Windows ping
命令的输出通过管道传输到缓冲区中以发送到我的函数。
I have the following code for linux:
char pi[512];
FILE *fp1;
char pingStr[250];
sprintf(pingStr, "ping %s", info->server);
fp1 = popen(pingStr,"r");
fgets(pi,512,fp1);
fgets(pi,512,fp1);
Send("%s\r\n",pi); //my function
fclose(fp1);
Is there a Windows equivalent? Because I could not seem to get it too work.
What I am trying to do is to pipe the output of the Windows ping
command into a buffer to send to my function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供的代码片段非常简单,因此您使用过的所有功能都有 Windows 等效项。这里是它们的文档:
可能导致错误的差异可能在于库名称您必须链接函数名称(有时以
_
开头)、头文件名、包含路径或其他。除非您提供足够的详细信息,否则很难准确说出您遇到的错误及其原因。除此之外,一切都应该像在 Linux 中一样工作。
The code snipped you have provided is extremely simple, so there are Windows equivalents for all of the functions you have used. Here they are with documentation:
The difference that can lead to error could be in library name you have to link with, function name (starting with
_
sometimes), header file name, include path or other. It is hard to tell exactly what error you experience and why, unless you provide enough details.Other than that, everything should work as in Linux.