0

在我之前的帖子中,我提出了一个关于 R 中西里尔符号的问题。今天我遇到了另一个问题。例如,我们想查看我们正在运行的进程:

    test <- system2(command="tasklist",
                   stdout=TRUE,
                   stderr=TRUE, 
                   wait = TRUE)

而我们所看到的...

 [1] ""                                                                            
 [2] "€¬п ®Ўа §                      PID €¬п бҐббЁЁ          ь ᥠ­б        Џ ¬пвм"
 [3] "========================= ======== ================ =========== ============"
 [4] "System Idle Process              0 Services                   0        24 ЉЃ"
 [5] "System                           4 Services                   0       580 ЉЃ"
 ***

"Iconv",这在上一个任务中有所帮助 - 在这里无济于事。

sys.setlocale- 也。

什么可以解决这个问题?

4

1 回答 1

1

我找到了解决方案。

#/c - Carries out the command specified by string and then stops.
command <- function(command, 
           intern = TRUE, 
           wait = FALSE)
system(paste("cmd.exe /c", command), 
           intern = T, 
           wait = wait)

#changing our charset
command("chcp 1251")
[1] "’ҐЄгй п Є®¤®ў п бва ­Ёж : 1251" //say bye-bye to mojibake)

# and voila!
command("tasklist")
[1] ""                                                                            
[2] "Имя образа                     PID Имя сессии          № сеанса       Память"
[3] "========================= ======== ================ =========== ============"
[4] "System Idle Process              0 Services                   0        24 КБ"
[5] "System                           4 Services                   0       580 КБ"
[6] "smss.exe                       380 Services                   0     1 232 КБ"
***
于 2021-09-16T16:39:45.457 回答