Perl and PHP do this with backticks. For example,
$output = `ls`;
Returns a directory listing. A similar function, system("foo")
, returns the operating system return code for the given command foo. I'm talking about a variant that returns whatever foo prints to stdout.
How do other languages do this? Is there a canonical name for this function? (I'm going with "backtick"; though maybe I could coin "syslurp".)
Python
Python <2.7 or <3.1
Extract
subprocess.check_output()
from subprocess.py or adapt something similar to:The subprocess module has been in the stdlib since 2.4.
Why there is still no c# guy here :)
This is how to do it in C#. The built-in way.
Ruby: either backticks or the '%x' builtin syntax.
Don't forget Tcl:
Clozure Common Lisp:
LispWorks
Python: