代码之家  ›  专栏  ›  技术社区  ›  Ed Mazur

SWIG生成的PHP扩展的stdout

  •  1
  • Ed Mazur  · 技术社区  · 14 年前

    我有以下C++功能:

    void foo() {
        std::cout << "bar" << std::endl;
    }
    

    foo() 但是我只看到 bar 如果从命令行运行PHP脚本,则输出。

    $ php script.php
    bar
    

    酒吧 在这种情况下?

    1 回复  |  直到 14 年前
        1
  •  1
  •   Artefacto    14 年前

    不能直接打印到标准输出。当然,这只有在使用CLI SAPI时才起作用。使用 php_printf 或其中任何一种:

    //Calls php_output_write
    #define PHPWRITE(str, str_len)
    //Calls php_output_write_unbuffered
    #define PHPWRITE_H(str, str_len)
    //Idem:
    #define PUTC(c)
    #define PUTC_H(c)
    #define PUTS(str)
    #define PUTS_H(str)
    int php_write(void *buf, uint size TSRMLS_DC);
    int php_printf(const char *format, ...);
    int php_output_write(const char *str, size_t len TSRMLS_DC);
    int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC);
    //see the rest of main/output.c