簡體   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