Hello Everyone,
I tried with different options, and searched a lot of blogs to get more details on the execution of python script within powershell FileWatcher script. The powershell FileWatcher could able to execute only powershell specific commands when the event is triggered, but not python script. Please help me out to execute the python script when the event is triggered.
$dir = 'C:\Users\XXXX\Documents\FileWatcher'
$filter = '*.*'
$Obj = New-Object IO.FileSystemWatcher $dir, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters] 'FileName, LastWrite'}
Register-ObjectEvent $Obj Created -SourceIdentifier FileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
## Executing python script ## test.py and this powershell script are located in same folder
C:\\Users\\XXXX\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe test.py ## --> tried with commands as well==> python test.py ### python.exe test.py
}
$Obj.EnableRaisingEvents = $true
do
{
Wait-Event -Timeout 5
} while ($true)