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

前端 未结 27 1238
误落风尘
误落风尘 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:48

    Icon/Unicon:

    stream := open("ls", "p")
    while line := read(stream) do { 
        # stuff
    }
    

    The docs call this a pipe. One of the good things is that it makes the output look like you're just reading a file. It also means you can write to the app's stdin, if you must.

提交回复
热议问题