2017-09-22 9 views
0

"PowerShell로 실행"을 마우스 오른쪽 단추로 클릭하고 선택하여 .ps1 스크립트를 시작하더라도이 문제는 시스템 계정으로 실행되는 FileSystemWatcher와 관련된 것으로 생각합니다.FileSystemWatcher를 사용하는 PowerShell 스크립트는 Python 스크립트를 실행하지 않습니다.

주 .ps1 스크립트에 명령을 통합하고 ACTION 이벤트 중에 다른 .ps1 스크립트를 시작하여 여러 가지 방법을 시도했습니다.

두 가지 모두 백엔드 기능을 수행하거나 \ naming \ deleting 및 파일 내용을 이동하지만 .py 스크립트 실행과 관련하여 현재 세션에서는 실행되지 않습니다.

누구나 그 창을 전경에서 시작하는 방법을 알고 있습니까? Python 코드는 플러그인 Selenium을 실행하므로 Chrome을 열어야합니다.

항상 감사드립니다. 내가 그것을 알아 냈 있도록

$folder = 'C:\scripts\tmp' # root path to monitor 
$filter = '*.*' # wildcard filter 

$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'} 

Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action { 
$name = $Event.SourceEventArgs.Name 
$changeType = $Event.SourceEventArgs.ChangeType 
$timeStamp = $Event.TimeGenerated 
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green 
Out-File -FilePath C:\Scripts\URLwatcher\logURL.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp" 

#Create a timestamp var 
$filetimestamp = (Get-Date -Format yyyy-mm-dd-hhmmss) 

#Create a timestamp file name 
$timestampedURLfile = "C:\Scripts\URLwatcher\processing\" + $filetimestamp + ".txt" 

#Move URL file and rename it 
move-item C:\scripts\tmp\data.txt $timestampedURLfile 

#Extract & store the URL from the file 
$addURL = Get-Content $filename 

#Scrape the url 
python C:\Scripts\DailyStats.py -l $addURL #### <--This script will not run #### 

#Delete the URL file 
del $filename 
} 

답변

0

확인 :

여기에 코드입니다. 작동 시키려면 Start-Process를 사용하여 다른 .ps1 스크립트를 시작해야했습니다.

.py 스크립트가 시작될 때 스크립트가 위치한 디렉토리를 다음과 같이 변경했습니다.

start-process powershell C:\Scripts\URLwatcher\ManualScrape.ps1 
---------------------------------------------------------------- 

#Debugger \\ Set-PSDebug -Trace 1 

#Create a timestamp var 
$movetimestamp = (Get-Date -Format yyyy-mm-dd-hhmmss) 

#Create a timestamp file name 
$timestampedURLfile = "C:\Scripts\URLwatcher\processing\" + $movetimestamp + ".txt" 

#Move URL file and rename it 
move-item C:\Scripts\tmp\data.txt $timestampedURLfile 

#Extract & store the URL from the file 
$addURL = Get-Content $timestampedURLfile 

#Run the scraper 
cd C:\Scripts 
python.exe DailyStats.py -l $addURL 

#Delete the URL file 
del $timestampedURLfile