【发布时间】:2021-05-07 08:27:01
【问题描述】:
我正在尝试使用 xargs 管道 python stdout 输出以 curl 并在此任务中失败。
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 打印输出以使上述命令正常工作?
【问题讨论】: