Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C语言中的任务列表,图像名称过滤器_C_Windows_Cmd_Tasklist - Fatal编程技术网

C语言中的任务列表,图像名称过滤器

C语言中的任务列表,图像名称过滤器,c,windows,cmd,tasklist,C,Windows,Cmd,Tasklist,我从一个用C编写的程序中运行tasklist命令,问题是我需要程序返回到屏幕,只返回“Image Name”列,而忽略其他列。有没有办法过滤它,只留下进程的名称,而不是PID列或其他 这是我的代码: #include <stdio.h> #include <string.h> int main(){ printf("IP number:\t"); scanf("%s", ip); sprintf(command, "tasklist /fo TABLE /nh /s

我从一个用C编写的程序中运行tasklist命令,问题是我需要程序返回到屏幕,只返回“Image Name”列,而忽略其他列。有没有办法过滤它,只留下进程的名称,而不是PID列或其他

这是我的代码:

#include <stdio.h>
#include <string.h>

int main(){

printf("IP number:\t");
scanf("%s", ip);

sprintf(command, "tasklist /fo TABLE /nh /s %s", ip);
system(command);

return 0;
}
#包括
#包括
int main(){
printf(“IP号码:\t”);
扫描频率(“%s”,ip);
sprintf(命令,“任务列表/fo表/nh/s%s”,ip);
系统(指挥部);
返回0;
}

使用
popen
而不是
system
,然后您可以在显示输出之前对其进行处理。或者在显示之前将输出导入文件进行处理。使用
>filename
你能给我举一个popen的例子吗?我不知道它是怎么工作的@这里有很多关于StackOverflow的例子,参见。