需要一种方法来确定文件是否被写入 [英] Need a way to determine if a file is done being written to

查看:134
本文介绍了需要一种方法来确定文件是否被写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所处的情况是这样的 - 有一个写入文件的过程,有时文件比较大,比如400-500MB。我需要知道什么时候写完了。我怎样才能确定这一点?如果我查看目录,我会在那里看到它,但是可能没有写完。另外,这需要远程完成 - 就像在同一个内部局域网上,而不是在同一台计算机上一样,通常情况下,想要知道文件写入完成的过程是在一个正在写入文件的进程的Linux机器上运行的,该文件本身在一个窗口框。没有桑巴不是一个选项。 xmlrpc通信到一个窗口的服务是一个选项,以及使用snmp来检查是否可行。



理想情况下




  • 可在Linux或Windows上运行 - 这意味着解决方案与操作系统无关。

  • 适用于任何类型的文件。



足够好:


  • 只适用于Windows,但可以通过一些库或任何可以通过Python访问的方式来完成。

  • PDF文件。


    当前最好的想法是定期打开窗口框上的某个进程的问题文件,并查看最后一个字节检查PDF结束标记,并考虑到eol的差异,因为这个文件可能已经在Linux或Windows上创建。

最终解决了我们的情况。事实证明,把文件写出来的过程让他们完全打开,所以我们所要做的只是尝试打开它们进行读取访问 - 当被拒绝时,它们就被使用了。

The situation I'm in is this - there's a process that's writing to a file, sometimes the file is rather large say 400 - 500MB. I need to know when it's done writing. How can I determine this? If I look in the directory I'll see it there but it might not be done being written. Plus this needs to be done remotely - as in on the same internal LAN but not on the same computer and typically the process that wants to know when the file writing is done is running on a Linux box with a the process that's writing the file and the file itself on a windows box. No samba isn't an option. xmlrpc communication to a service on that windows box is an option as well as using snmp to check if that's viable.

Ideally

  • Works on either Linux or Windows - meaning the solution is OS independent.
  • Works for any type of file.

Good enough:

  • Works just on windows but can be done through some library or whatever that can be accessed with Python.
  • Works only for PDF files.

Current best idea is to periodically open the file in question from some process on the windows box and look at the last bytes checking for the PDF end tag and accounting for the eol differences because the file may have been created on Linux or Windows.

解决方案

I ended up resolving it for our situation. As it turns out the process that was writing the files out had them opened exclusively so all we had to do was try opening them for read access - when denied they were in use.

这篇关于需要一种方法来确定文件是否被写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆