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

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

    In shell

    OUTPUT=`ls`
    

    or alternatively

    OUTPUT=$(ls)
    

    This second method is better because it allows nesting, but isn't supported by all shells, unlike the first method.

提交回复
热议问题