[1.1.0] Windows: Different character encoding running in IDE and from commandline

Asked by Max on 2018-07-10

Hello,

i have a sikulix script which has a different behaviour when i start it as a batch file with runsikulix.cmd than running it from the IDE
 .
I'm using Sikulix 1.1.0 (cant download a newer version because it is restricted in my companys network)

the script copys (type ctrl+c -> Env.getClipboard()) some mail text with special characters like "ä", "ö" or "ü" and paste it into a textbox of another application.
when i start my script from the sikulix IDE everything is fine.
but when i start my script from a batch file (\\xxxxxx\SikuliX\runsikulix.cmd -r \\xxxx\test.sikuli). the encoding of the special characters fails. The chacater "ä" is displayed as "ÿ".
how can i fix that?

thank you for your help!

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-07-26
Last reply:
2018-07-26
RaiMan (raimund-hocke) said : #1

using print?

if yes: try with uprint()

this is from the sources (Lib/sikuli/Sikuli.py):

##
# some support for handling unicode and strings
#
## use instead of print if unicode strings present
# usage: uprint(s1, u1, u2, u3, s3, ...)
#
def uprint(*args):
  for e in args[:-1]:
    if isinstance(e, str):
      print e,
    else:
      print e.encode("utf8"),
  if isinstance(args[-1], str):
    print args[-1]
  else:
    print args[-1].encode("utf8")

##
# to make an utf8-encoded string from a str object
#
def unicd(s):
  return ucode(s)

def ucode(s):
  return (unicode(s, "utf8"))

Max (extreme1337) said : #2

no i‘m using „paste(myvariable)“ to paste the string into the textbox.

Max (extreme1337) said : #3

and yes: i did the .encode.decode utf-8 thing with my variable

RaiMan (raimund-hocke) said : #4

Uuups, should have read your message more carefully, sorry.

What system? What Java?

could you please paste the offending code snippet?

Max (extreme1337) said : #5

I'm running Sikulix 1.1.0 on Windows 7 64bit, Java Version 8, Update 152.

Here is my code snippet with some comments:

###########################################
type("c",KEY_CTRL) # copy selected mail subject field
mail = Env.getClipboard()
mail = mail.encode('utf-8', 'ignore').decode('utf-8')
mail = mail.split("\n") # split table titles line and subject/sender
mail = mail[1] # set var mail to the subject/sender string
mail = mail.split("\t") # split into sender and subject
sender = "sender unknown"
sender = mail[0] #sender name
sender = sender.encode('utf-8', 'ignore').decode('utf-8')
mailtext = "no text"
mailtext = mail[1] # subject text
mailtext = mailtext.encode('utf-8', 'ignore').decode('utf-8')
#switch to textbox (ticket application)
paste("Here is some text from "+sender+": "+mailtext)
###########################################

Thank you for your help

Max (extreme1337) said : #6

Value of mail is for example:

From Subject Received Size
Lastname, Firstname Subjecttext 22:09 46 KB

Launchpad Janitor (janitor) said : #7

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Max (extreme1337) said : #8

the issue still exists. can i provide more helpful information? just tell me what you need. thanks a lot!

RaiMan (raimund-hocke) said : #9

sorry for ignoring.
I will take a look now.

RaiMan (raimund-hocke) said : #10

ok, tested with 1.1.0 and 1.1.3 on Windows 10 latest Java 8.

This finally worked for me:

text = Env.getClipboard() # contains Unicode chars
uprint(text) # does not print correctly on commandline (known problem)

text1 = "ööööööööööööööööö"
text2 = ucode(text1)

#text = text + "\n" + text1 # does not work (ascii codec error)
text = text + "\n" + text2 # works
uprint(text) # see above
paste(text) # works bot in IDE and from commandline

conclusion:
- assigning with Env.getClipboard() works

- adding text with Unicode chars using + only works if text is encoded correctly (using ucode(text) or unicode(text, "utf8"))

paste(text) works in all cases

Can you help with this problem?

Provide an answer of your own, or ask Max for more information if necessary.

To post a message you must log in.