gpt4 book ai didi

r - 在 R 中抑制 system() 输出

转载 作者:行者123 更新时间:2023-12-05 08:41:27 25 4
gpt4 key购买 nike

我想将 invisible() 函数行为应用于我在脚本中得到的输出,如下所示 system("cmd.exe", input = command) .但是,即使使用 invisible,输出仍然显示在控制台中。有什么办法可以隐藏吗?

编辑:我在命令中运行 curl 以下载网页,输出是预期的 curl 输出。

EDIT2:可重现的例子

url <- "www.google.com"
command <- paste0('curl "',
url,
'"',
' -H "Pragma: no-cache" -H "Accept-Encoding: gzip, deflate, br" -H "Accept-Language: en-US,en;q=0.9" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" -H "Cache-Control: no-cache" -H "Cookie: uupid69991=eb4c8ec5-1f94-4cf5-957d-e477a778f79c; uupid99993=eb4c8ec5-1f94-4cf5-957d-e477a778f79c; uupid89991=1; uupid79991=Fee_Based_Role; locale=en; uupid99991=1903 x 1012; IVZSESSIONID=CEHrDvYqpDuQ-zwy8YZpWwm1RWZHY3DGq4V7elBfxcH87XFFo-J_^! -175310928; _ga=GA1.2.1974800928.1524362050; _gid=GA1.2.1544243785.1524362050" -H "Connection: keep-alive" --compressed',
' > google.html')

invisible(system("cmd.exe", input = command))

控制台输出:

Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\gonza\OneDrive\Documents\etfcmfa>curl "www.google.com" -H "Pragma: no-cache" -H "Accept-Encoding: gzip, deflate, br" -H "Accept-Language: en-US,en;q=0.9" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" -H "Cache-Control: no-cache" -H "Cookie: uupid69991=eb4c8ec5-1f94-4cf5-957d-e477a778f79c; uupid99993=eb4c8ec5-1f94-4cf5-957d-e477a778f79c; uupid89991=1; uupid79991=Fee_Based_Role; locale=en; uupid99991=1903 x 1012; IVZSESSIONID=CEHrDvYqpDuQ-zwy8YZpWwm1RWZHY3DGq4V7elBfxcH87XFFo-J_^! -175310928; _ga=GA1.2.1974800928.1524362050; _gid=GA1.2.1544243785.1524362050" -H "Connection: keep-alive" --compressed > google.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 231 100 231 0 0 982 0 --:--:-- --:--:-- --:--:-- 982

最佳答案

在您的系统调用中使用 intern=TRUE。来自 system 帮助页面:

intern  
a logical (not NA) which indicates whether to capture the output of the command as an R character vector.

完成后,您可以使用 invisible 或只存储结果以防止它们被打印。

关于r - 在 R 中抑制 system() 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49987319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com