Veröffentlicht 11. Dezember 200024 j hallo leutens, kann mir jemand mal ein anwendungsbeispiel für popen() hier reinpasten? ich muß aus einem c proggie heraus ein ls machen und will die dateien, die normalerweise in der konsole angezeigt werden, in einem string speichern ... danke !! poldi
11. Dezember 200024 j Hi Das hier ist aus Visual C++ vielleicht hilft dir ja das weiter dein Hasi /* POPEN.C: This program uses _popen and _pclose to receive a * stream of text from a system process. */ #include <stdio.h> #include <stdlib.h> void main( void ) { char psBuffer[128]; FILE *chkdsk; /* 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( (chkdsk = _popen( "dir *.c /on /p", "rt" )) == NULL ) exit( 1 ); /* Read pipe until end of file. End of file indicates that * CHKDSK closed its standard out (probably meaning it * terminated). */ while( !feof( chkdsk ) ) { if( fgets( psBuffer, 128, chkdsk ) != NULL ) printf( psBuffer ); } /* Close pipe and print return value of CHKDSK. */ printf( "\nProcess returned %d\n", _pclose( chkdsk ) ); } Output Volume in drive C is CDRIVE Volume Serial Number is 0E17-1702 Directory of C:\dolphin\crt\code\pcode 05/02/94 01:05a 805 perror.c 05/02/94 01:05a 2,149 pipe.c 05/02/94 01:05a 882 popen.c 05/02/94 01:05a 206 pow.c 05/02/94 01:05a 1,514 printf.c 05/02/94 01:05a 454 putc.c 05/02/94 01:05a 162 puts.c 05/02/94 01:05a 654 putw.c 8 File(s) 6,826 bytes 86,597,632 bytes free Process returned 0
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.