curl PowerShell工作正常,批处理文件不工作

iqjalb3h  于 2022-11-13  发布在  Shell
关注(0)|答案(1)|浏览(193)

我有一个PowerShell脚本,它运行良好-它下载一个Google电子表格,并将其保存为target.csv:

curl https://some-url.com -O target.csv

当我尝试通过批处理脚本执行此操作时:

start powershell curl https://some-url.com -O target.csv

它不保存文件。我已经尝试了它也与>> target.csv和我得到的文件没有内容。
它应该在安装了PowerShell 1和curl.exe的Windows 2008服务器上运行

**编辑:**我的实际bat文件:

start powershell -noexit curl https://docs.google.com/spreadsheets/d/e/2PACX-1vSV966X52f-JvdpwnJbFGeHFlG7uR48069MtD4tvPRintmqH_O2JEclIg6knXkKUuO-dGEhS69LdM1P/pub?gid=556715578&single=true&output=csv -O target.csv

当我在URL使用""时,我会遇到以下错误:

In Zeile:1 Zeichen:151
+ ... tvPRintmqH_O2JEclIg6knXkKUuO-dGEhS69LdM1P/pub?gid=556715578&&single=t ...
+                                                                ~~
Das Token "&&" ist in dieser Version kein gültiges Anweisungstrennzeichen.
In Zeile:1 Zeichen:164
+ ... JEclIg6knXkKUuO-dGEhS69LdM1P/pub?gid=556715578&&single=true&&output=c ...
+                                                                ~~
Das Token "&&" ist in dieser Version kein gültiges Anweisungstrennzeichen.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine

如果没有"",则开始下载,但不下载所需的数据:

StatusCode        : 200
StatusDescription : OK
Content           : <!DOCTYPE html><html><head><title>Kleine Zeitung Paid Content</title><meta name="viewport" content=
                    "target-densitydpi=device-dpi,user-scalable=1,minimum-scale=1,maximum-scale=2.5,initial-scale=1,wid
                    th...
RawContent        : HTTP/1.1 200 OK
                    X-Robots-Tag: noindex, nofollow, nosnippet
                    Cache-Control: private, max-age=300
                    Content-Type: text/html; charset=utf-8
                    Date: Thu, 07 Mar 2019 12:36:20 GMT
                    Expires: Thu, 07 Mar 2019...
Forms             : {}
Headers           : {[X-Robots-Tag, noindex, nofollow, nosnippet], [Cache-Control, private, max-age=300],
                    [Content-Type, text/html; charset=utf-8], [Date, Thu, 07 Mar 2019 12:36:20 GMT]...}
Images            : {}
InputFields       : {}
Links             : {@{innerHTML=Google Sheets; innerText=Google Sheets; outerHTML=<A title="Learn more about Google
                    Sheets" href="https://docs.google.com/spreadsheets/?usp=sheets_web" target=_blank>Google
                    Sheets</A>; outerText=Google Sheets; tagName=A; title=Learn more about Google Sheets;
                    href=https://docs.google.com/spreadsheets/?usp=sheets_web; target=_blank}, @{innerHTML=Missbrauch
                    melden; innerText=Missbrauch melden; outerHTML=<A href="https://docs.google.com/abuse?id=e/2PACX-1v
                    SV966X52f-JvdpwnJbFGeHFlG7uR48069MtD4tvPRintmqH_O2JEclIg6knXkKUuO-dGEhS69LdM1P">Missbrauch
                    melden</A>; outerText=Missbrauch melden; tagName=A; href=https://docs.google.com/abuse?id=e/2PACX-1
                    vSV966X52f-JvdpwnJbFGeHFlG7uR48069MtD4tvPRintmqH_O2JEclIg6knXkKUuO-dGEhS69LdM1P}}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 2179532

Edit 2我们发现问题出在&上,因此我尝试了许多变体,%26\&&amp;'&'"&",但没有一个能正常工作。

当我通过PowerShell手动启动它时,它工作正常,作为一个 bat ,它不工作-大多是相同的错误(错误1)。
因此,我需要找到一种方法来使用批处理文件中的&

编辑3

  • 终于解决 *
"https://docs.google.com/spreadsheets/d/e/2PACX-1vSV966X52f-JvdpwnJbFGeHFlG7uR48069MtD4tvPRintmqH_O2JEclIg6knXkKUuO-dGEhS69LdM1P/pub?gid=556715578'&'single=true'&'output=csv"

正如您所看到的,问题/解决方案是双引号和单引号,谢谢!

zf2sa74q

zf2sa74q1#

感谢您@Compo!
我也总是得到一个目标.csv,要么是空的,要么是有“错误”的数据。
这是&的一个问题,最终我们解决了它:

"http://....'&'....'&'...."

"谢谢你"

相关问题