티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

How do I watch a file for changes?

파일의 변경을 어떻게 확인합니까?

 문제 내용 

I have a log file being written by another process which I want to watch for changes. Each time a change occurs I'd like to read the new data in to do some processing on it.

다른 프로세스에서 작성 중인 로그 파일이 있어 변경 사항을 확인할 수 있습니다. 변경 사항이 발생할 때마다 새 데이터를 읽어서 일부 처리를 수행하고 싶습니다.

 

What's the best way to do this? I was hoping there'd be some sort of hook from the PyWin32 library. I've found the win32file.FindNextChangeNotification function but have no idea how to ask it to watch a specific file.

이것을 하는 가장 좋은 방법은 무엇입니까? 저는 PyWin32 라이브러리의 후크 같은 것이 있기를 바랐다. 나는 win32file.FindNextChangeNotification 함수를 찾았지만, 특정 파일을 보도록 요청하는 방법을 모릅니다.

 

If anyone's done anything like this I'd be really grateful to hear how...

만약 이런 일을 해본 사람이 있다면 어떻게...

 

[Edit] I should have mentioned that I was after a solution that doesn't require polling.

[편집] 폴링이 필요하지 않은 솔루션을 원한다고 언급했어야 했습니다.

 

[Edit] Curses! It seems this doesn't work over a mapped network drive. I'm guessing windows doesn't 'hear' any updates to the file the way it does on a local disk.

[편집] 매핑된 네트워크 드라이브에서는 작동하지 않는 것 같습니다. 저는 Windows가 로컬 디스크에서 하는 방식으로 파일에 대한 업데이트를 '듣지' 못하는 것 같습니다.

 

 

 

 높은 점수를 받은 Solution 

Did you try using Watchdog?

Watchdog를 사용해 보셨습니까?

 

Python API library and shell utilities to monitor file system events.

Directory monitoring made easy with

  • A cross-platform API.
  • A shell tool to run commands in response to directory changes.

Get started quickly with a simple example in Quickstart...

파일 시스템 이벤트를 모니터링하는 Python API 라이브러리 및 셸 유틸리티.

디렉토리 모니터링이 용이함

- 크로스 플랫폼 API입니다.
- 디렉토리 변경에 응답하여 명령을 실행하는 셸 도구입니다.

Quickstart...의 간단한 예제로 빠르게 시작하세요.

 

 

 

 가장 최근 달린 Solution 

Seems that no one has posted fswatch. It is a cross-platform file system watcher. Just install it, run it and follow the prompts.

아무도 fswatch를 게시하지 않은 것 같습니다. 크로스 플랫폼 파일 시스템 감시자입니다. 설치하고 실행한 후 메시지를 따릅니다.

 

I've used it with python and golang programs and it just works.

나는 그것을 파이썬과 golang 프로그램과 함께 사용했고 잘 작동합니다.

 

 

 

출처 : https://stackoverflow.com/questions/182197/how-do-i-watch-a-file-for-changes

반응형
댓글
공지사항
최근에 올라온 글