gpt4 book ai didi

powershell - 从 Shell 脚本向 PowerShell 传递命令

转载 作者:行者123 更新时间:2023-12-03 01:03:11 26 4
gpt4 key购买 nike

我有一些 Windbg 脚本,我可以在其中通过 .shell 命令调用 cmd shell。现在我想执行一些 Windbg 命令并将输出通过管道传输到应该启动 powershell.exe 以处理输入数据的 shell 脚本。到目前为止,我确实失败了。

原则上应该可以将数据从 stdin 传递到 powershell 管道?

echo C: | powershell.exe -Command "| dir" 

我不想创建额外的 powershell 脚本,因为这会使 windbg 脚本进一步复杂化并创建外部依赖项。

最佳答案

您可以使用预定义的 $input 变量来使用回显到 powershell 中的文本。结合管道,这完美地工作:

echo C:\ | powershell.exe -command "$input | dir"

编辑:您还需要使用 echo C:\。我不确定其中的原因,只是简单地编写 Get-ChildItem 'C:' 默认为当前目录。

关于powershell - 从 Shell 脚本向 PowerShell 传递命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52969817/

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