I want to do run a Linux command from a Mathematica notebook. I see, that Mathematica and my Linux operating system use different character coding.
The problem is that the directories and the file names in my file system also use non-ASCII characters (which is legal in Unix).
According to the Unix command
locale, I have
According to Mathematica,
$CharacterEncoding returns me
(Btw: in the documentation WRI speaks about
"UTF-8". Is there any difference? If both are synonymous and if really both forms have to be used somewhere in Mathematica commands or options, would it be possible to let the (probably less frequent) use of "UTF-8" automatically be substituted for
"UTF8" if someone calls a function's option that way?)
If I use file or path names which look right in Mathematica (indeed, they were made by a copy/paste operation via the clipboard from the Linux file browser to Mathematica), the non-ASCII characters in the strings become garbled through the standard handling of the command
Run: However it should translate its parameter "command" such that all characters are translated in the right way to let the operating system sees them in its own encoding: Exactly in the same way as if the OutputForm of the parameter would have been copied to the clipboard and it would have been pasted from there to a terminal. Since my operating system speaks
"de_DE.UTF-8", the parameter command should be translated to the character encoding of the host system:
Für deutsch braucht man äÄöÖüÜ und ß. Pour le français, il faut aussi áÁâÂÀàéÉêÊÈèùÙëËïÏæÆœŒçÇ et les guillemets « et ». For other European languages other characters, accents, carons, macrons are customary with the Latin alphabet.
Since all these characters are legal in file- an directory names in Linux, there should be a way to also pass them to a command with
Is there a function for the outbound translation (i.e. from Mathematica to UTF8) such that the argument of Run[command] is treated that way such that the Linux system gets them transformed?
Run["echo \"ähnlich, üblich oder örtlich\" > ~/file"] produces a file with this content:
Ã¤hnlich, Ã¼blich oder Ã¶rtlich
How would one overload
Run such that it accepts an additional parameter (or an option,
CharacterEncoding->"UTF8") which it currently does not have?
Note: A similar but different question about conversion of file content has been asked by me recently here. But this question is different because it deals with file names, not with their content.