codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <assert.h> #include <stdio.h> #include <string.h> #include <unistd.h> int make_popen(void) { FILE *fd = NULL; char buf[4096]; size_t len = 0; fd = popen("/bin/echo hello world", "r"); len = fread(buf, 1, 11, fd); if (len != 11) return 1; buf[11] = '\0'; pclose(fd); if (strcmp(buf, "hello world") != 0) return 2; return 0; } int main(int argc, char **argv) { int success = -1; FILE *fd = NULL; assert(daemon(0, 0) == 0); fd = fopen("/tmp/result", "w"); assert(fd != NULL); success = make_popen(); fprintf(fd, "result: %i\n", success); fclose(fd); return success; }
Private
[
?
]
Run code
Submit