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

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

    Yet another way to do it in Perl (TIMTOWTDI)

    $output = <<`END`;
    ls
    END
    

    This is specially useful when embedding a relatively large shell script in a Perl program

提交回复
热议问题