拦截(使用Python)数据从另一个进程写入文件

时间:2019-04-16 20:37:50

标签: python python-3.x windows intercept

我正在做一些将来可能会派上用场的事情。

有人知道我可以(通过Python)(通过某种其他语言/过程)拦截被写入文件的数据的方法吗?

我会知道要拦截的文件的路径,并且最好是希望找到一种可以在Windows上运行的解决方案。我知道watchdog可以监视文件更改,但我的目标是在写操作接触文件之前对其进行拦截。

例如,他们在我的计算机上运行以下脚本,该脚本不断不断地写入文件:

import time
filename = "testfile"
i = 1
while True:
    with open(filename, 'a') as out:
        out.write(str(i) + '\n')
        time.sleep(1)
        i += 1

注意:这只是一个示例。我要拦截的数据不是用Python编写的。我不知道它写的是什么。

在另一个脚本中,我想截取写入testfile的所有内容。

我不相信这是可能的,但我想我会问。

1 个答案:

答案 0 :(得分:0)

Using os.walk you can make a list of how many files you have in your whole directory and then keep checking it and cross reference it with a previous variable that says what the file count is, and when there is a difference you can open it using os.open.

相关问题