Reputation: 11757
I need to process a video file, and I need the file to be completed before I open it. So I need to check if the file is opened or not before processing it, but opened by another process. Any idea how to check this? I'm using Linux.
Upvotes: 5
Views: 1491
Reputation: 16265
Without any additional gems, a slightly wasteful way might be:
if %x[lsof -F n].split("\n").grep(/yourfilename/).empty?
# all clear
else
end
Or
if system %Q[lsof #{filename}]
# still open..
else
# all clear
end
Or, ignore my hacked suggestion and use a gem for this: https://github.com/jordansissel/fosl
Upvotes: 8