首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell -将两条管道合并为一条管道

Powershell -将两条管道合并为一条管道
EN

Stack Overflow用户
提问于 2020-09-11 15:04:40
回答 1查看 85关注 0票数 2

我正在使用Powershell (版本5.1.17763.1007),并希望将两个管道合并为一个管道。它们的内容非常相似;它们分别使用Pylint和prospector递归地从文件夹中查找Python文件到它的子文件夹中,并为这些Python文件生成linting报告(参见https://www.pylint.org/https://pypi.org/project/prospector/ )。

代码语言:javascript
复制
$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)做过实验,这是最好的方法吗?我正在寻找类似这样的东西(伪代码):

代码语言:javascript
复制
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"
                   }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-11 15:08:35

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

代码语言:javascript
复制
$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"
                   }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63842280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档