找不到接受參數 --disable-gpu 的位置參數

找不到接受參數 --disable-gpu 的位置參數

我正在嘗試建立一個 powershell 進程,在其中我可以透過自動化列印本機網頁。

start-process "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --print-to-pdf="C:\Temp\createPdf180304023549.pdf" http://localhost/

但問題是它一直說

找不到接受參數 --disable-gpu 的位置參數

但是,我正在使用的命令是從複製的https://developers.google.com/web/updates/2017/04/headless-chrome

我做錯了什麼?

答案1

將參數新增ArgumentList到您的命令中,如下所示:

start-process "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -ArgumentList @"--headless --disable-gpu --print-to-pdf="C:\Temp\createPdf180304023549.pdf" http://localhost/"

請注意,參數已用雙引號引起來,並在前面添加了 at 符號 (@),以轉義 print-to pdf 參數中的雙引號。

如果沒有此參數,PowerShell 會將用於 Chrome 的參數解釋為 Start-Process cmdlet 的參數。


啟動進程

答案2

它對我有用

start-process chrome.exe -ArgumentList "--headless --print-to-pdf=C:\Users\{User}\Desktop\AllPdf\pdf4.pdf https://www.google.com"

相關內容