lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Please have a look at the popen2() example on that page.

Perfect! (I thought I'd seen something exactly like this before, and of course I had, on that page :-)

The popen2() function is so splendidly useful I'd suggest that you build it right into the ex API/package itself.

Forgive my ignorance, but why do you need two pipes...in other words, why like this:

  local in_rd, in_wr = io.pipe()
  local out_rd, out_wr = io.pipe()
  local proc, err = os.spawn{stdin = in_rd, stdout = out_wr, ...}

and not like this:

  local rd, wr = io.pipe()
  local proc, err = os.spawn{stdin = rd, stdout = wr, ...}

or is that an artifact [sp?] of how spawn() is implemented?

Pity that Linux's and Windows's popen() isn't bidirectional like the BSDs' are, as Rici correctly observes in his post.

(The FreeBSD man page even points out that "historically, popen() was implemented with a unidirectional pipe; hence many implementations of popen() only allow the type argument to specify reading or writing, not both. Since popen() is now implemented using a bidirectional pipe, the type argument may request a bidirectional data flow.")