Python POWERSHELL:如何在POWERSHELL中运行管道工具?

Python POWERSHELL:如何在POWERSHELL中运行管道工具?,python,powershell,Python,Powershell,目标: 我必须运行的版本,但无法运行: $: Get-ChildItem -File | ForEach-Object { $_.ToString() } foo1 foo2 $: Get-ChildItem -File | ..\..\python\modules\foo.py hello-file $_.ToString() hello, foo1! hello, foo2! BASH等效于上述命令: Get-ChildItem -File | ForEach-Object {.

目标:

我必须运行的版本,但无法运行:

$: Get-ChildItem -File | ForEach-Object { $_.ToString() }

foo1
foo2

$: Get-ChildItem -File | ..\..\python\modules\foo.py hello-file $_.ToString()

hello, foo1!
hello, foo2!


BASH等效于上述命令:

Get-ChildItem -File | ForEach-Object {..\..\python\modules\foo.py hello-file $_.ToString()}

上述powershell代码的结果:

运行python open和close的CMD windows实例;没有输出通过管道传输到终端


如何在powershell中执行此壮举?可以避免更改python代码吗?

我不太确定python文件的内部工作原理,但我想您会发现这有助于:

Get ChildItem-File | ForEach对象{python..\\ python\modules\foo.py hello File$\ uu0.ToString()}
添加单词“python”将导致脚本直接在当前shell中运行。 因此,任何错误/结果都将打印在您可以看到的地方


当我在运行时没有显式键入“python”时,一个单独的python终端被打开并立即关闭。

我不太清楚python文件的内部工作原理,但我想您会发现这有助于:

Get ChildItem-File | ForEach对象{python..\\ python\modules\foo.py hello File$\ uu0.ToString()}
添加单词“python”将导致脚本直接在当前shell中运行。 因此,任何错误/结果都将打印在您可以看到的地方


当我没有显式输入“python”就运行时,一个单独的python终端被打开并立即关闭。

运行/非工作版本打印了什么?@uumm一点也没有;但是,如果我为同一个python脚本编写
--help
,我会得到格式正确的内容。在引擎盖下,脚本直接打开,“/dev/stdout”;也许这有打开cmd窗口的效果?从运行/非工作版本打印什么?@uumm根本没有;但是,如果我为同一个python脚本编写
--help
,我会得到格式正确的内容。在引擎盖下,脚本直接打开,“/dev/stdout”;也许这有打开cmd窗口的效果?
# path vars are set
$: ls | xargs -I {} foo.py hello-file {}

hello, foo1!
hello, foo2!