[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua / shell - How to "pipe" commands in os.execute() ?
- From: David Given <dg@...>
- Date: Wed, 04 Apr 2007 10:57:38 +0100
luc1an0 wrote:
[...]
> My question can be very stupid, but I want to execute some shell
> commands with a pipe ( | ) like that :
> os.execute(ps aux | grep my_program) or a generic way :
> os.execute("my_command" "my_args" | another_command | ....)
I may be missing something here, but:
os.execute("ps aux | grep my_program")
...should work.
> And another simply question : How to don't return exit code if function
> even return string, for example
> io.write(os.execute("pwd")) return this
> /home/fred
> 0
I'm not sure what you're asking for here. Do you want to stop pwd printing
it's output directly to the console and instead let Lua capture it as a
string? If so, use io.popen:
local f = io.popen("pwd") -- runs command
local l = f:read("*a") -- read output of command
print(l)
f:close()
Or did you mean something else?
--
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│ "Thou who might be our Father, who perhaps may be in Heaven, hallowed be
│ Thy Name, if Name Thou hast and any desire to see it hallowed..." ---
│ _Creatures of Light and Darkness_
Attachment:
signature.asc
Description: OpenPGP digital signature