gpt4 book ai didi

python - Powershell-将两个管道合并为一个

转载 作者:行者123 更新时间:2023-12-02 23:49:39 25 4
gpt4 key购买 nike

我正在使用Powershell(版本5.1.17763.1007),并希望将两个管道合并为一个。
它们的内容非常相似。
他们递归地从文件夹中的子文件夹中查找Python文件,
并分别使用Pylint和exploror为这些Python文件生成更新报告
(请参阅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"
}

最佳答案

为什么不依次执行两个命令?

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

关于python - Powershell-将两个管道合并为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63842280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com