免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: SybaseLU
打印 上一主题 下一主题

查找文件不通过文件名 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-12-17 19:53 |只看该作者
原帖由 yylogo 于 2008-12-17 19:43 发表
楼上,请你教我popen怎么用。
学习Ing....:wink: :wink:
我是新手.

名字记错了 是_popen,下面是msdn的例子
// crt_popen.c

/* This program uses _popen and _pclose to receive a
 * stream of text from a system process.
 */


#include <stdio.h>
#include <stdlib.h>

int main( void )
{

&nbsp;&nbsp;&nbsp;char   psBuffer[128];
&nbsp;&nbsp;&nbsp;FILE   *pPipe;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* Run DIR so that it writes its output to a pipe. Open this
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* pipe with read text attribute so that we can read it
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* like a text file.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/


&nbsp;&nbsp;&nbsp;if( (pPipe = _popen( "dir *.c /on /p", "rt" )) == NULL )
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit( 1 );

&nbsp;&nbsp;&nbsp;/* Read pipe until end of file, or an error occurs. */

&nbsp;&nbsp;&nbsp;while(fgets(psBuffer, 128, pPipe))
&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(psBuffer);
&nbsp;&nbsp;&nbsp;}


&nbsp;&nbsp;&nbsp;/* Close pipe and print return value of pPipe. */
&nbsp;&nbsp;&nbsp;if (feof( pPipe))
&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf( "\nProcess returned %d\n", _pclose( pPipe ) );
&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf( "Error: Failed to read the pipe to the end.\n");
&nbsp;&nbsp;&nbsp;}
}

论坛徽章:
0
12 [报告]
发表于 2008-12-17 20:28 |只看该作者
哦,谢谢..

论坛徽章:
0
13 [报告]
发表于 2008-12-17 23:43 |只看该作者

回复 #10 Fixend 的帖子

How does grep command can retrieve context of non-text files like PNG, MP3, or MP4?

论坛徽章:
0
14 [报告]
发表于 2008-12-17 23:59 |只看该作者
原帖由 SybaseLU 于 2008-12-17 23:43 发表
How does grep command can retrieve context of non-text files like PNG, MP3, or MP4?


grep只支持文本文件。
你先回答我,对于PNG,你用什么作为key来查找?
你只能用某种方式来标记这个PNG,而且是可读的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP