Making a system call that returns the stdout output as a string

前端 未结 27 1146
误落风尘
误落风尘 2020-11-27 05:13

Perl and PHP do this with backticks. For example,

$output = `ls`;

Returns a directory listing. A similar function, system(\"foo\")

27条回答
  •  隐瞒了意图╮
    2020-11-27 05:53

    In C on Posix conformant systems:

    #include  
    
    FILE* stream = popen("/path/to/program", "rw");
    fprintf(stream, "foo\n"); /* Use like you would a file stream. */
    fclose(stream);
    

提交回复
热议问题