Different character encoding when using CMD instead of IDE

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:
Open
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-07-10
Last reply:
2018-07-10
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

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.