如何解决西里尔符号(cmd 系统命令)的问题?
How to fix a problem with Cyrillic symbols (cmd system commands)?
在我之前的 中,我提出了一个关于 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
- 也是。
什么可以解决这个问题?
我找到了解决方案。
#/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 КБ"
***
在我之前的
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
- 也是。
什么可以解决这个问题?
我找到了解决方案。
#/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 КБ"
***