[英]Powershell - Combine two pipelines into one
I am using Powershell (version 5.1.17763.1007), and wish to combine two pipelines into one.我正在使用 Powershell(版本 5.1.17763.1007),并希望将两个管道合二为一。 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/ )
他们递归地从文件夹中查找 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"
}
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?我已经尝试过 Tee-Object Cmdlet ( https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7 ),这是最好的方法? 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"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.