7

The documentation for RunThrough["command",expr] says that it executes an external command and returns the result. Does that mean it executes it as if on the command line? Why does this not return the string "blah" (or maybe "blah\r\n")?

RunThrough["echo","blah"]

(I'm on Windows.)

CarbonFlambe
  • 1,234
  • 8
  • 13

1 Answers1

6

That

RunThrough["echo", "blah"]

doesn't work appears strange because on my system, OS X, which means the terminal command line is talking to Free BSD Unix, man echo gives

echo -- write arguments to the standard output

Further, both

RunThrough["cat", "blah"]

and

RunThrough["echo blah", ""]

work.

Update

It turns out the operative phrase in my quote from the Unix man page is "write arguments". That is, echo does not accept input from standard input. It only writes the arguments that follow the token echo on the command line to standard output. The documentation for RunThrough says the second argument is passed to the OS command mentioned in the first argument by standard input. I assume this means pipped in.

This explains the behavior encountered by the OP and why RunThrough["echo blah", ""] works.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257