繁体   English   中英

如何清洁 Windows 上的 python print() output 用于管道?

[英]How to clean python print() output on Windows for piping?

我正在尝试 pipe python 标准输出 output 与 xargs 到 ZF6E57C9DE709E45FEB0D9 在此任务中失败。

curl 可以接受来自 echo 的输入

λ echo https://google.com | xargs curl
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

但是当从 python 打印相同内容时,xargs curl 输入在 Windows(使用 cmder)上变得无效。

这在 WSL 中运行良好:

python3 -c"print('https://google.com')" | xargs curl
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

但是在 Windows 上可能有一些换行符/换行符干扰:

λ python -c"print('https://google.com')" | xargs curl
curl: (3) URL using bad/illegal format or missing URL

如何在 Windows 上清理 python print output 以使上述命令起作用?

应该猜到了!

python -c"print('https://google.com', end='')" | xargs curl

如何在没有换行符或空格的情况下打印?

我太喜欢为 xargs 找到一些可以完成所有工作的论据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM