wizawu
wizawu

Reputation: 2081

How can Erlang os:cmd/1 run a command with Unicode characters?

5> os:cmd("touch 编程").

exception error: no function clause matching os:validate1([32534,31243]) (os.erl, line 330)
in function os:cmd/1 (os.erl, line 165)

Upvotes: 3

Views: 1204

Answers (2)

l04m33
l04m33

Reputation: 606

Well, if your shell's locale is UTF-8, just do this:

os:cmd(binary_to_list(unicode:characters_to_binary("touch 编程")))

But in source files, you can simply write

os:cmd("touch 编程").

And save the file in UTF-8, then everything will work fine.

Seems that the Erlang parser had done something special to the literal strings.

Upvotes: 2

Svetlin Mladenov
Svetlin Mladenov

Reputation: 4427

Erlang uses latin1 for its source files which means that you cannot use chinese or any other symbols which are not in the latin1 encoding directly in the code.

The easiest way to achieve what you whant is:

Name = [231,188,150,231,168,139,10].
os:cmd("touch " ++ Name).

Upvotes: 4

Related Questions