TechieGuy12 / FileWatcher

A file and folder monitor that can send notifications, perform actions, or execute a command when a file or folder is changed.
MIT License
106 stars 27 forks source link

Commands don't seem to be working #31

Closed openSourcerer9000 closed 1 year ago

openSourcerer9000 commented 1 year ago

So I'm trying to run a .bat file that just does this for now:

ECHO "hello world!"
ECHO %1
pause

This is my config.xml:

<watches>
    <logging>
        <!--
            The full path to the log file.

            Default: %TEMP%\fw.log
        -->
        <path>C:\log\fw.log</path>
    </logging>
    <!-- A folder watch-->
    <watch>
        <!-- 
            Path of the folder to watch. File and folder exclusions are relative
            to the value specified in this element.
        -->
        <path>C:\Users\seanm\Desktop\temp\fw</path>
        <!--
            The amount of seconds to wait for the path to exist before
            establishing the watch. This timeout can be used with paths that
            are on external hard drives that may not be connected for a time
            when FileWatcher is started.
        -->
        <!-- <timeout></timeout> -->
                <!--
            Perform actions when a change is detected.
        -->
        <actions>
            <action>
                <!--
                    What events will trigger the action.

                    Values:
                        Change
                        Create
                        Delete
                        Rename
                -->
                <triggers>
                    <trigger>Create</trigger>
                </triggers>            
                <!--
                    The type of action to perform.

                    Values:
                        Copy
                        Move
                        Delete
                -->
                <type>Copy</type>
                <!--
                    The source path of the action. 

                    Placeholders:
                        [exactpath] - full path of the changed file
                        [fullpath] - full path of the changed file without the path of the watch
                        [path] - the path of the changed file without the path of the watch and the file
                        [file] - the name of the file with the extension
                        [filename] - name of the file without the extension
                        [extension] - the file extension
                -->
                <source>[exactpath]</source>
                <!--
                    The destination path of the action.
                    This value does not apply to the Delete action.

                    Placeholders:
                        [exactpath] - full path of the changed file
                        [fullpath] - full path of the changed file without the path of the watch
                        [path] - the path of the changed file without the path of the watch and the file
                        [file] - the name of the file with the extension
                        [filename] - name of the file without the extension
                        [extension] - the file extension
                        [createddate:format]
                        [modifieddate:format]
                        [currentdate:format]
                -->
                <destination>C:\log\[file]</destination>
                <!--
                    Verifies the file after a copy or move.

                    Values:
                        true
                        false (default)
                -->
              <verify>true</verify>
            </action>
        </actions>
        <!--
            Run commands when a change is detected.
        -->
        <commands>
            <command>
                <!--
                    What events will trigger the command.

                    Values:
                        Change
                        Create
                        Delete
                        Rename
                -->
                <triggers>
                    <trigger>Create</trigger>
                </triggers>            
                <!--
                    The path of the command to run.

                    Placeholders:
                        [exactpath] - full path of the changed file
                        [fullpath] - full path of the changed file without the path of the watch
                        [path] - the path of the changed file without the path of the watch and the file
                        [file] - the name of the file with the extension
                        [filename] - name of the file without the extension
                        [extension] - the file extension
                -->            
                <path>C:\app\test.bat</path>
                <!--
                    The arguments of the command to run.

                    Placeholders:                    
                        [exactpath] - full path of the changed file
                        [fullpath] - full path of the changed file without the path of the watch
                        [path] - the path of the changed file without the path of the watch and the file
                        [file] - the name of the file with the extension
                        [filename] - name of the file without the extension
                        [extension] - the file extension
                -->                   
                <arguments>"[fullpath]"</arguments>
            </command>
        </commands>    
    </watch>
</watches>

I'm running filewatcher from the cmd prompt. The action works just fine, but nothing happens either in the cmd prompt or the log to suggest it tried to run the command. My log file only logs when the watch begins, and when actions are performed, not that a new file has been created.


2023-03-22 10:19:07 INFO Creating watch for C:\Users\seanm\Desktop\temp\fw.
2023-03-22 10:19:07 INFO Watch created for C:\Users\seanm\Desktop\temp\fw.
2023-03-22 10:19:20 INFO Copied C:\Users\seanm\Desktop\temp\fw\New Text Document.txt to C:\log\New Text Document.txt. Verify: True. Keep timestamps: False.
2023-03-22 10:19:28 INFO Copied C:\Users\seanm\Desktop\temp\fw\f - Copy - Copy (3) - Copy.txt to C:\log\f - Copy - Copy (3) - Copy.txt. Verify: True. Keep timestamps: False.

Is there something I might be doing wrong? thanks

Windows 10

openSourcerer9000 commented 1 year ago

OK, so I filled out the batch script with what I really want to do - activate python and run a script.

It seems like what's happening is that the console doesn't get passed through to filewatcher. This appears in the log now: 2023-03-22 11:07:50 INFO The execution 'C:\app\test.bat "C:\Users\seanm\Desktop\temp\fw\myfile.txt"' has exited. Exit code: 0. I assume this means there was an error in either my bat file or python code? How can I let it print from the console for debugging? - especially if it could log it that would be ideal.

TechieGuy12 commented 1 year ago

Can you try this beta release: 1.5.0-beta?

This release should redirect standard output to the log file.

openSourcerer9000 commented 1 year ago

Perfect, works great!