Execute one process for 30 seconds and get the output
I need to run a process for 30 seconds and while it is running I have to store the output in a text file. After 30 seconds I'd have to destroy the process. I know how to run the process and how to store data in a file but don't know how to do it for 30 seconds only (the process would take much longer 开发者_Go百科if not stopped).
Thanks.
How about:
my_long_command & sleep 30 && kill %+
(Still need to make sure %1 will always reference that job, I'm checking how)
P.S I'm assuming you're talking about shell command execution? The answer I gave works in bash
EDIT: Changed %1 to %+
精彩评论