RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1004306
Accepted
Adollo
Adollo
Asked:2020-07-18 20:20:20 +0000 UTC2020-07-18 20:20:20 +0000 UTC 2020-07-18 20:20:20 +0000 UTC

通过 RScript.exe 运行脚本时,R shell() 函数未将结果保存到向量?

  • 772

脚本“wget_test.R”:

print(paste0('OUT:', shell("bash -c 'wget https://www.ft.com -O out.html'", intern = TRUE)))

我在 R 控制台中运行:

 [1] "OUT:Will not apply HSTS. The HSTS database must be a regular and non-world-writable file."
 [2] "OUT:ERROR: could not open HSTS store at '/home/adollo/.wget-hsts'. HSTS will be disabled."
 [3] "OUT:--2019-07-18 14:58:46--  https://www.ft.com/"                                         
 [4] "OUT:Resolving www.ft.com (www.ft.com)... 151.101.246.109"                                 
 [5] "OUT:Connecting to www.ft.com (www.ft.com)|151.101.246.109|:443... connected."             
 [6] "OUT:HTTP request sent, awaiting response... 200 OK"                                       
 [7] "OUT:Length: 446829 (436K) [text/html]"                                                    
 [8] "OUT:Saving to: вЂ\u0098out.html’"                                                       
 [9] "OUT:"                                                                                     
[10] "OUT:     0K .......... .......... .......... .......... .......... 11%  851K 0s"          
[11] "OUT:    50K .......... .......... .......... .......... .......... 22% 1.65M 0s"          
[12] "OUT:   100K .......... .......... .......... .......... .......... 34% 47.7M 0s"          
[13] "OUT:   150K .......... .......... .......... .......... .......... 45% 51.5M 0s"          
[14] "OUT:   200K .......... .......... .......... .......... .......... 57%  636K 0s"          
[15] "OUT:   250K .......... .......... .......... .......... .......... 68% 36.9M 0s"          
[16] "OUT:   300K .......... .......... .......... .......... .......... 80% 47.7M 0s"          
[17] "OUT:   350K .......... .......... .......... .......... .......... 91% 51.0M 0s"          
[18] "OUT:   400K .......... .......... .......... ......               100% 47.2M=0.2s"        
[19] "OUT:"                                                                                     
[20] "OUT:2019-07-18 14:58:46 (2.46 MB/s) - вЂ\u0098out.html’ saved [446829/446829]"          
[21] "OUT:"

我在 Windows 终端中运行“RScript wget_test.R”:

Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '/home/adollo/.wget-hsts'. HSTS will be disabled.
--2019-07-18 14:59:03--  https://www.ft.com/
Resolving www.ft.com (www.ft.com)... 151.101.246.109
Connecting to www.ft.com (www.ft.com)|151.101.246.109|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 446759 (436K) [text/html]
Saving to: ‘out.html’

out.html                      100%[=================================================>] 436.29K  --.-KB/s    in 0.1s

2019-07-18 14:59:03 (3.07 MB/s) - ‘out.html’ saved [446759/446759]

[1] "OUT:"

我也试过系统功能 - 结果是一样的。

结果差异的原因可能是什么?

R 控制台中的 sessionInfo():

R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=Russian_Russia.1251  LC_CTYPE=Russian_Russia.1251    LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C                   
[5] LC_TIME=Russian_Russia.1251    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rvest_0.3.4 xml2_1.2.0 

loaded via a namespace (and not attached):
 [1] httr_1.4.0     compiler_3.6.0 selectr_0.4-1  magrittr_1.5   R6_2.4.0       tools_3.6.0    curl_3.3       Rcpp_1.0.1     stringi_1.4.3 
[10] stringr_1.4.0 

sessionInfo() 通过 RScript.exe:

R version 3.6.0 (2019-04-26) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale: [1] LC_COLLATE=Russian_Russia.1251  LC_CTYPE=Russian_Russia.1251 [3] LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C [5] LC_TIME=Russian_Russia.1251

attached base packages: [1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached): [1] compiler_3.6.0
shell
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    aleksandr barakin
    2020-07-19T06:24:46Z2020-07-19T06:24:46Z

    通常,wget程序将消息写入标准错误流 ( stderr )。您只需要将其重定向到与标准输出流 ( stdout ) 相同的位置。

    相比:

    > print(paste0('out:',system('wget -O y.html http://ya.ru',intern=T)))
    --2019-07-19 01:18:15--  http://ya.ru/
    Resolving ya.ru (ya.ru)... 87.250.250.242, 2a02:6b8::2:242
    Connecting to ya.ru (ya.ru)|87.250.250.242|:80... connected.
    HTTP request sent, awaiting response... 302 Found
    Location: https://ya.ru/ [following]
    --2019-07-19 01:18:15--  https://ya.ru/
    Connecting to ya.ru (ya.ru)|87.250.250.242|:443... connected.
    HTTP request sent, awaiting response... 200 Ok
    Length: 13607 (13K) [text/html]
    Saving to: ‘y.html’
    
    y.html              100%[===================>]  13.29K  --.-KB/s    in 0.02s
    
    2019-07-19 01:18:15 (768 KB/s) - ‘y.html’ saved [13607/13607]
    
    [1] "out:"
    

    所以:

    > print(paste0('out:',system('wget -O y.html http://ya.ru 2>&1',intern=T)))
     [1] "out:--2019-07-19 01:18:32--  http://ya.ru/"
     [2] "out:Resolving ya.ru (ya.ru)... 87.250.250.242, 2a02:6b8::2:242"
     [3] "out:Connecting to ya.ru (ya.ru)|87.250.250.242|:80... connected."
     [4] "out:HTTP request sent, awaiting response... 302 Found"
     [5] "out:Location: https://ya.ru/ [following]"
     [6] "out:--2019-07-19 01:18:32--  https://ya.ru/"
     [7] "out:Connecting to ya.ru (ya.ru)|87.250.250.242|:443... connected."
     [8] "out:HTTP request sent, awaiting response... 200 Ok"
     [9] "out:Length: 13610 (13K) [text/html]"
    [10] "out:Saving to: ‘y.html’"
    [11] "out:"
    [12] "out:     0K .......... ...                                        100%  714K=0.02s"
    [13] "out:"
    [14] "out:2019-07-19 01:18:32 (714 KB/s) - ‘y.html’ saved [13610/13610]"
    [15] "out:"
    
    • 1

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    根据浏览器窗口的大小调整背景图案的大小

    • 2 个回答
  • Marko Smith

    理解for循环的执行逻辑

    • 1 个回答
  • Marko Smith

    复制动态数组时出错(C++)

    • 1 个回答
  • Marko Smith

    Or and If,elif,else 构造[重复]

    • 1 个回答
  • Marko Smith

    如何构建支持 x64 的 APK

    • 1 个回答
  • Marko Smith

    如何使按钮的输入宽度?

    • 2 个回答
  • Marko Smith

    如何显示对象变量的名称?

    • 3 个回答
  • Marko Smith

    如何循环一个函数?

    • 1 个回答
  • Marko Smith

    LOWORD 宏有什么作用?

    • 2 个回答
  • Marko Smith

    从字符串的开头删除直到并包括一个字符

    • 2 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5