Is there a method by which I can view c function printf log out?

Issue #388 resolved
Jinjie Zhang
created an issue

I use cffi to call c function in python. But I can't view c function printf output.

test.c

#include <stdio.h>
int test_output(int n) {
    printf("log %d", n);
}

test_build.py

from cffi import FFI
ffi = FFI()
ffi.cdef('''
int test_output(int n);
''')
ffi.set_source('pytest', '''
#include "test.h"
''', sources=['test.c'])
if __name__ == '__main__':
     ffi.compile(verbose=True)

test code:

from pytest import lib, ffi
lib.test_output(10)

The code line lib.test_output(10) has no output.

Comments (3)

  1. Jinjie Zhang reporter

    I know the reason. printf format needs a '\n' newline. I change test_output to the following, It will work:

    int test_output(int n) {
        print("log %d\n", n);
    }
    
  2. Log in to comment