In my nginx+lua app OS executing a command line something like os.execute("ls 2>&1 | tee a.txt")
I want to know does it block main app? I want use command "execute-and-forgot" case. If it blocks how to fix it and execute a simple line in background thread?
os.execute() will block for the time of execution of the command you are running and since you generate some output, using io.popen
won't help you much as you'd need to read from the pipe (otherwise the process will still block at some point).
A better way may be to run the process in the background: os.execute("ls >a.txt 2>&1 &")
. The order of redirects >
and 2>
matters and the &
at the end will run the command in the background, unblocking os.execute
.
os.execute()
is equivalent to system()
in C, therefore it blocks the thread.
If you don't want to block, use io.popen
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With