l-out.c

来自「The pipe "|" char in linux rewrite in C.」· C语言 代码 · 共 66 行

C
66
字号
/*l-out.c simple pipe .c , you can ripper it if you need.  compile with gcc l-out.c -o l-out  usage :  bash-2.05a$ ./ciao "nmap localhost" lupo  bash-2.05a$ cat lupo  Starting nmap V. 3.00 ( www.insecure.org/nmap/ )  Interesting ports on localhost (127.0.0.1):  (The 1595 ports scanned but not shown below are in state: closed)  Port       State       Service  21/tcp     open        ftp                       23/tcp     open        telnet                    25/tcp     open        smtp                      587/tcp    open        submission                6000/tcp   open        X11                       6699/tcp   open        napster                    Nmap run completed -- 1 IP address (1 host up) scanned in 1 second  bash-2.05a$*/ #include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>void usage(){ fprintf (stdout,"l-out.c [command] [filelog]\n"); exit(0);}int main( int argc, char** argv ){ FILE* f; FILE* record; char *recordstring; char *command;     if (argc<3) usage();    command=argv[1];     if ( ( record = fopen(argv[2],"wb")) == NULL ) 	{      	perror("fopen" );      	exit (0);    	}	    if( ( f = popen( buffer, "r" ) ) == NULL ) 	{    	perror( "popen" );    	return EXIT_FAILURE;    	}    while(!feof(f))    	{    	recordstring=malloc(sizeof(recordstring));    	fgets(recordstring,sizeof(recordstring),f);    	fprintf (record,"%s",recordstring);    	}    fclose(record);    pclose( f );    return EXIT_SUCCESS; }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?