微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我运行 powershell 文件时,函数中没有运行 git 命令?

如何解决当我运行 powershell 文件时,函数中没有运行 git 命令?

当我更改目录中的文件时,会监视和记录更改,但 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 举报,一经查实,本站将立刻删除。