2

Possible Duplicate:
Get back the output of os.execute in Lua

I want to assign the result of a shell command to a lua variable.

Any better way in lua 5.1 than what is answered here? Get back the output of os.execute in Lua

Community
  • 1
  • 1
ripat
  • 3,076
  • 6
  • 26
  • 38
  • Did I forget to polity say hello or something??? – ripat May 17 '11 at 16:10
  • 1
    Sorry, I missed the "in lua 5.1" comment, so I guess this isn't an exact dup that already linked to the duplicate post. What platform are you using that doesn't have `io.popen` or why isn't that good enough for your needs? – BMitch May 17 '11 at 16:15
  • No offense. I was indeed hoping changes with the 5.1 version. Something like `luaVar = io.execute('shell_cmd')`. I will go the `io.popen` way that is compiled in my version. ^_^ – ripat May 17 '11 at 17:00
  • Since 5.1 was released in Feb 2006 (latest fixes in Sept 2008), the linked question almost certainly implied 5.1. – BMitch May 17 '11 at 17:23

1 Answers1

3

You can use io.popen for this (included in Lua 5.1). That gives you a file handle which you can use to either write or read from (to) the program. More info in the Lua Manual.

jpjacobs
  • 9,359
  • 36
  • 45