I want my script to be able to take input from stdin where the data might be provided in UTF8 or UTF16 encoding.
something like:
datasource | my-script -e utf8
How do I set the external_encoding of stdin ?
In the first line of the script where you define ruby
as the interpreter, you may add the --encoding utf-8
parameter in order specify the stdin encoding.
#!/usr/bin/env ruby --encoding utf-8
text = ARGF.read
man ruby
:-E external[:internal] --encoding external[:internal] Specifies the default value(s) for external encodings and internal encoding. Values should be separated with colon (:). You can omit the one for internal encodings, then the value (Encoding.default_internal) will be nil.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With