Stopping Nasty IO using Cython

750 days ago by wstein

%cython cdef extern from "fcntl.h": cdef int STDOUT_FILENO cdef int O_WRONLY int dup(int) void dup2(int, int) int open(char*, int, int) void close(int) def NASTY(): printf("Nasty!\n"); def tryit(): cdef int stdout_save, stdout_null stdout_save = dup(STDOUT_FILENO) stdout_null = open("/dev/null", O_WRONLY, 0) dup2(stdout_null, STDOUT_FILENO) # CALL_YOUR_NASTY_FUNCTION() NASTY() dup2(stdout_save, STDOUT_FILENO); close(stdout_save) close(stdout_null) 
NASTY() 
       
Nasty!
Nasty!
tryit() 
       
 
       
5
5