0

In my previous post, I brought up a question about Cyrillic symbols in R. Today I have faced another one. For example, we want to see our running processes:

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

and what we see...

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

"Iconv", which helped in the previous task - couldn't help here.

sys.setlocale - too.

What can solve this problem?

Dharman
  • 30,962
  • 25
  • 85
  • 135
manro
  • 3,529
  • 2
  • 9
  • 22
  • What is the output of the command `chcp`? – lit Sep 15 '21 at 00:58
  • @lit I have by default - ```866``` An output to txt file from the console has also unreadable letters. When i change ```chcp``` to ```1251``` - text in the file can be readable, but output in the RStudio console is again corrupted. ```chcp 65001``` - columns have been translated into english (console and output file; RStudio console still has "mojibake"). – manro Sep 15 '21 at 07:04
  • If `tasklist.exe` is run from a `cmd.exe` prompt or PowerShell console, is the output correct? – lit Sep 15 '21 at 14:43
  • @lit Hmmm, interesting. The displaying in ```1) cmd.exe``` and ```2) PowerShell``` console is same - all right. But ```tasklist > c:\\tasklist1.txt``` in the first case (without activating ```chcp 1251```) has corrupted symbols, in the second - all ok. – manro Sep 15 '21 at 18:40
  • @lit I found a solution \ (*_*) / – manro Sep 16 '21 at 16:27

1 Answers1

1

I found a solution.

#/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 КБ"
***
Dharman
  • 30,962
  • 25
  • 85
  • 135
manro
  • 3,529
  • 2
  • 9
  • 22