[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua / shell - How to "pipe" commands in os.execute() ?
- From: luc1an0 <luc1an0@...>
- Date: Wed, 04 Apr 2007 12:16:11 +0200
David Given a écrit :
yes, works great... When i 've tried to do that, i had some bash errors.
Probably due to an incorrect syntax...
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")
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
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
Or did you mean something else?
"pwd" was just an example... In fact, if I execute command which return
a status code (like "test"), I want to get it. But if the command return
a string, I just want to get these string without the status code.
Thanks a lot :)