7
$\begingroup$

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

$\endgroup$
  • $\begingroup$ @Mr.Wizard. I still think echo writes to Window's equivalent of stdout. $\endgroup$ – m_goldberg Feb 8 '17 at 3:22
  • $\begingroup$ Given the way RunThrough works, the expression that will give you the behavior you expect is RunThrough["cat", "blah"] $\endgroup$ – m_goldberg Feb 8 '17 at 5:57
6
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ RunThrough["echo blah", ""] works on Windows too. +1 and disregard my earlier comments. (I'll delete them later after people have had ample chance to see and laugh at them. :o) $\endgroup$ – Mr.Wizard Feb 8 '17 at 3:29
  • $\begingroup$ So it was the input channel rather than the output channel that was the problem. Thanks for tracking that down. $\endgroup$ – Mr.Wizard Feb 8 '17 at 6:22
  • $\begingroup$ @Mr.Wizard. Yes $\endgroup$ – m_goldberg Feb 8 '17 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.