问题描述
当我更改目录中的文件时,会监视和记录更改,但 git 命令在 powershell 脚本中不起作用。
$filewatcher.Path =$args
write-host $filewatcher.Path
$filewatcher.Filter = "*.*"
$filewatcher.IncludeSubdirectories = $true
$filewatcher.EnableRaisingEvents = $true
$writeaction = { $path = $Event.sourceEventArgs.FullPath
$changeType = $Event.sourceEventArgs.ChangeType
$logline = "$(Get-Date),$changeType,$path"
Add-content "D:\FileWatcher_log.txt" -value $logline
}
$pushaction = {
write-host $filewatcher.Path
$path = $Event.sourceEventArgs.FullPath
$changeType = $Event.sourceEventArgs.ChangeType
$logline = "$(Get-Date),$path"
write-host $logline
git -C $filewatcher.Path add .
git -C $filewatcher.Path commit -m $logline
git -C $filewatcher.Path push
}
Register-ObjectEvent $filewatcher "Created" -Action $pushaction
Register-ObjectEvent $filewatcher "Changed" -Action $pushaction
Register-ObjectEvent $filewatcher "Deleted" -Action $pushaction
Register-ObjectEvent $filewatcher "Renamed" -Action $pushaction
while ($true) {sleep 5}
shell 上的输出看起来像-:
C:\Users\ABHIJEET>PowerShell.exe -ExecutionPolicy Unrestricted -command "C:\users\abhijeet\desktop\test\backup-win.ps1" C:\Users\Abhijeet\Desktop\test\
C:\Users\Abhijeet\Desktop\test\
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 8eb075d3-923... NotStarted False ...
2 bb594e1a-742... NotStarted False ...
3 ae2a4956-ca2... NotStarted False ...
4 4241104d-994... NotStarted False ...
04/01/2021 17:36:38,Created,C:\Users\Abhijeet\Desktop\test\New Text Document.txt
04/01/2021 17:36:43,Renamed,C:\Users\Abhijeet\Desktop\test\file2.txt
git 命令没有运行。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)