473,385 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Watching a file another app is writing

I'm trying to find a way to take a file that another program has opened
and writes to periodically, open it simultaneously in Python, and
automatically update some of my objects in Python when the file is
written to.
I can open the file and manually readlines() from it to keep up to date,
it's the automatic part I'm having trouble with. This is on Windows.
Mar 11 '07 #1
8 1957
On Mar 11, 3:36 pm, Gordon Airporte <JHoo...@fbi.govwrote:
I'm trying to find a way to take a file that another program has opened
and writes to periodically, open it simultaneously in Python, and
automatically update some of my objects in Python when the file is
written to.
I can open the file and manually readlines() from it to keep up to date,
it's the automatic part I'm having trouble with. This is on Windows.
You might need to look at pywin32 for Windows specific ways to listen
to "file changed" event.

On Unix a quick shortcut would be to simply read the output of 'tail -
f <file>' command...

Mar 12 '07 #2
Nick Vatamaniuc wrote:
You might need to look at pywin32 for Windows specific ways to listen
to "file changed" event.

On Unix a quick shortcut would be to simply read the output of 'tail -
f <file>' command...
Ah, I forgot I have Cygwin installed, so I do have tail. Unfortunately
Windows will not let most programs save to the file while tail is
watching it, and when I force it with vim :w! the output from tail -f
does not update. Maybe I'm using it wrong.
Well, off to dig through windows documentation. Then I have to figure
out how to write and event loop for the shell.
Mar 12 '07 #3
En Mon, 12 Mar 2007 04:25:48 -0300, Gordon Airporte <JH*****@fbi.gov>
escribió:
Nick Vatamaniuc wrote:
You might need to look at pywin32 for Windows specific ways to listen
to "file changed" event.
This article explains it in detail:
http://tgolden.sc.sabren.com/python/...r_changes.html
BTW, it's the top result on Google for "python notify file change windows"

--
Gabriel Genellina

Mar 12 '07 #4
Gordon Airporte schreef:
Nick Vatamaniuc wrote:
You might need to look at pywin32 for Windows specific ways to listen
to "file changed" event.

On Unix a quick shortcut would be to simply read the output of 'tail -
f <file>' command...

Ah, I forgot I have Cygwin installed, so I do have tail. Unfortunately
Windows will not let most programs save to the file while tail is
watching it, and when I force it with vim :w! the output from tail -f
does not update. Maybe I'm using it wrong.
Have you tried with tail -F instead of tail -f? With a big F it uses the
name of the file instead of the file descriptor, and it keeps trying to
open the file. I'm not sure if it will work, but it's worth a shot.

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
Mar 12 '07 #5
Nick Vatamaniuc wrote:
On Mar 11, 3:36 pm, Gordon Airporte <JHoo...@fbi.govwrote:
>>I'm trying to find a way to take a file that another program has opened
and writes to periodically, open it simultaneously in Python, and
automatically update some of my objects in Python when the file is
written to.
I can open the file and manually readlines() from it to keep up to date,
it's the automatic part I'm having trouble with. This is on Windows.


You might need to look at pywin32 for Windows specific ways to listen
to "file changed" event.

On Unix a quick shortcut would be to simply read the output of 'tail -
f <file>' command...
"tail -f" just checks the file size once a second. It's not doing
anything exciting.

Windows, of course, actually has a mechanism for finding out that
files have changed, so that will work.

Note that if you're doing this as a means of interprocess
communication, there are better ways.

John Nagle
Mar 12 '07 #6
Gordon Airporte wrote:
I'm trying to find a way to take a file that another program has opened
and writes to periodically, open it simultaneously in Python, and
automatically update some of my objects in Python when the file is
written to.
I can open the file and manually readlines() from it to keep up to date,
it's the automatic part I'm having trouble with. This is on Windows.
It occurs to me under Unix you could perhaps get your first program to write
to a "named pipe", which you 2nd program could read from. See

http://en.wikipedia.org/wiki/Named_pipe

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Mar 12 '07 #7
In article <js*****************@newssvr25.news.prodigy.net> , John Nagle wrote:
>On Unix a quick shortcut would be to simply read the output of 'tail -
f <file>' command...

"tail -f" just checks the file size once a second. It's not doing
anything exciting.
That's not actually always true these days. *BSD, at least, use
'kqueue' to avoid busy-wait on "tail -f".
Mar 12 '07 #8
Gabriel Genellina wrote:
This article explains it in detail:
http://tgolden.sc.sabren.com/python/...r_changes.html

BTW, it's the top result on Google for "python notify file change windows"

--Gabriel Genellina
Ah, excelent. Thank you. I'd started with the pywin32 documentation,
where I did manage to find FindFirstChangeNotification(). I had to go to
bed before I could get to Google to figure out how to use it.
Having just tested it, it seems that my problem is now caching. These
only trigger when the file is written to disk, and for the small amounts
of data I'm dealing with that's not with every transaction.
This is probably why tail wasn't working for me either, with the added
complication of it locking the file.
Mar 12 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Christopher Harrison | last post by:
I would like to, cleanly, watch a flat file for changes (updates and the like). The file will be altered by another program... I found some example code (which actually didn't compile) on Google,...
6
by: Ajay Pal Singh | last post by:
Hi, I am creating a web service, which needs to take some actions based on the config file. I need a way to listen the changes as they occur in the config file so that the service can take...
7
by: Claire | last post by:
Im sat here watching task manager and the memory consumption of my application rising second by second. What tools are there out there for me to use to find where it's all going please? (I wish...
2
by: Stu | last post by:
Hi, I have been asked to interface with an AIX system running a COBOL application. Not having done this before we settled on text files written to a drive to communicate between the two systems....
15
by: xkenneth | last post by:
Hi, I'm writing a couple python applications that use the serial port (RS-232) quite extensively. Is there any way I can monitor all activity on the serial port and have it printed as the...
11
by: jcor | last post by:
Can anyone give me some help, plz I want to create a perl script to be watching a folder. Everytime a new file gets there it triggers some code; How can I do this? TIA, João Correia
14
by: Zed A. Shaw | last post by:
Hi Everyone, Just putting out an announcement that I've released a new version of Vellum numbered 0.16. This version should be ready for people to use as not much of the internal structure has...
5
by: Andrew Cooper | last post by:
I've got an application that I'm modifying and the client needs it to watch a particular file and then do some stuff when that file gets modified. For example, let's say the file is C:\Test.dat...
3
by: canabatz | last post by:
Hi all i got a page that is refreshing data in a grid every 4 seconds and displaying results from the database and check if something as changed! my question is if there is 100 users that is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.