我正在使用Powershell (版本5.1.17763.1007),并希望将两个管道合并为一个管道。它们的内容非常相似;它们分别使用Pylint和prospector递归地从文件夹中查找Python文件到它的子文件夹中,并为这些Python文件生成linting报告(参见https://www.pylint.org/和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"
}我已经用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"
}发布于 2020-09-11 15:08:35
为什么不依次执行这两个命令呢?
$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"
}https://stackoverflow.com/questions/63842280
复制相似问题