将目录内容作为单行传递给 Powershell 中的可执行文件

发布于 2024-08-07 06:19:06 字数 290 浏览 3 评论 0原文

我有一个二进制可执行文件,它采用文件路径列表作为参数,例如,

C:\Tool.exe C:\Files\File1.txt C:\Files\File2.txt

我想从 Powershell 调用此工具。问题是,如何将 get-childitem 的输出全部放在一行上?

如果我运行:

ls C:\Files\*.txt |选择全名

我每行得到一个路径。我如何连接结果?

I have a binary executable that takes a list of file paths as arguments, e.g.,

C:\Tool.exe C:\Files\File1.txt C:\Files\File2.txt

I would like to call this tool from Powershell. The question is, how can I get the output of get-childitem all on one line?

If I run:

ls C:\Files\*.txt | select FullName

I get one path per line. How can I concatenate the results?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2024-08-14 06:19:06

在 PowerShell 2.0 中,您可以使用 -join 运算符:

(ls C:\Files\*.txt | %{ $_.FullName }) -join ' '

在 PowerShell 1.0 中,您可以设置 $OFS,它用于在将项目序列用作字符串时组合它们:

$ofs = ' '
"$(ls C:\Files\*.txt | %{ $_.FullName })"

In PowerShell 2.0 you can use the -join operator:

(ls C:\Files\*.txt | %{ $_.FullName }) -join ' '

In PowerShell 1.0 you can set $OFS, which is used to combine a sequence of items when they are used as a string:

$ofs = ' '
"$(ls C:\Files\*.txt | %{ $_.FullName })"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文