Tuesday, March 23, 2010

Capturing system command output as a string

Programmer Question

Perl and PHP do this with backticks. For example:



$output = `ls`;


This code returns a directory listing into the variable $output. A similar function, system("ls"), returns the operating system return code for the given command. I'm talking about a variant that returns whatever the command prints to stdout. (There are better ways to get the list of files in a directory; the example code is an example of this concept.)



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".)



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails