原帖由 yylogo 于 2008-12-17 19:40 发表
楼上,有什么办法可以直接将dos中获取的东西转到C里面来?
个人认为应该是不能的吧。。
应该要用到>将内容存到文件里,再在C里面读取才可以吧?
// 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 ) { char psBuffer[128]; FILE *pPipe; /* Run DIR so that it writes its output to a pipe. Open this * pipe with read text attribute so that we can read it * like a text file. */ if( (pPipe = _popen( "dir *.c /on /p", "rt" )) == NULL ) exit( 1 ); /* Read pipe until end of file, or an error occurs. */ while(fgets(psBuffer, 128, pPipe)) { printf(psBuffer); } /* Close pipe and print return value of pPipe. */ if (feof( pPipe)) { printf( "\nProcess returned %d\n", _pclose( pPipe ) ); } else { printf( "Error: Failed to read the pipe to the end.\n"); } } |
原帖由 SybaseLU 于 2008-12-17 23:43 发表
How does grep command can retrieve context of non-text files like PNG, MP3, or MP4?
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |