简体   繁体   中英

Powershell - Combine two pipelines into one

I am using Powershell (version 5.1.17763.1007), and wish to combine two pipelines into one. Their contents are very similar; They recursively look for Python files from a folder into it's subfolders, and generate linting-reports for these Python files, using Pylint and prospector respectively (see https://www.pylint.org/ and https://pypi.org/project/prospector/ )

$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"
                   }

I have experimented with the Tee-Object Cmdlet ( https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7 ), is that the best approach? I am looking for something like this (pseudo-code):

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"
                   }

why not execute the two commands after each other?

$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"
                   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM