I am trying to run a program which generate files while it is being watched (in order to achieve that I am using multi-threading) my code looks like that:
import threading
from threading import Thread
import os
import subprocess
def delete_folder_content():
import shutil
folder = r"C:/watch"
for the_file in os.listdir(folder):
file_path = os.path.join(folder, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path): shutil.rmtree(file_path)
except Exception as e:
print(e)
def watcher():
command = r"C:/git_private/test-engineer-code-task/dist/node10-win-x64/index-win.exe -w C:/watch"
os.system(command)
def generate():
delete_folder_content()
command = r"C:/git_private/test-engineer-code-task/dist/node10-win-x64/index-win.exe -g 50 -o C:/watch"
os.system(command)
if __name__ == "__main__":
Thread(target=watcher).start()
Thread(target=generate).start()
I want to be able to get the output being produced from "watcher()" method which listens to a specific folder and generate output when the folder gets populated with files.
is there a way to save to output? the output is dynamic.