[英]Powershell - Combine two pipelines into one
我正在使用 Powershell(版本 5.1.17763.1007),並希望將兩個管道合二為一。 它們的內容非常相似; 他們遞歸地從文件夾中查找 Python 文件到其子文件夾中,並分別使用 Pylint 和探礦者為這些 Python 文件生成 linting-reports(參見https://www.pylint.org/和https://pypi.org/project /探礦者/ )
$path_to_files = "C:\Users\$env:UserName\Desktop\my_project_folder\linter_reports"
# Get all Python modules in folder and generate Pylint reports
Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
ForEach-Object { pylint $_.Name |
Out-File -FilePath "pylint_results_$($_.Name.TrimEnd(".py")).txt"
}
# Get all Python modules in folder and generate Prospector reports
Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
ForEach-Object { prospector $_.Name |
Out-File -FilePath "prospector_results_$($_.Name.TrimEnd(".py")).txt"
}
我已經嘗試過 Tee-Object Cmdlet ( https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7 ),這是最好的方法? 我正在尋找這樣的東西(偽代碼):
Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
ForEach-Object Tee-Object { pylint $_.Name |
Out-File -FilePath "pylint_results_$($_.Name.TrimEnd(".py")).txt"
} |
{ prospector$_.Name |
Out-File -FilePath "prospector_results_$($_.Name.TrimEnd(".py")).txt"
}
為什么不依次執行這兩個命令?
$path_to_files = "C:\Users\$env:UserName\Desktop\my_project_folder\linter_reports"
# Get all Python modules in folder and generate Pylint and prospector reports
Get-ChildItem -Path $path_to_files -Recurse -Filter *.py |
ForEach-Object { pylint $_.Name |
Out-File -FilePath "pylint_results_$($_.Name.TrimEnd(".py")).txt"
prospector $_.Name |
Out-File -FilePath "prospector_results_$($_.Name.TrimEnd(".py")).txt"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.