Print Page | Close Window

python -c text not correct

Printed From: MetaCase
Category:
Forum Name: MetaEdit+
Forum Description: All topics relating to MetaEdit+ or DSM
URL: http://www.metacase.com/forums/forum_posts.asp?TID=915
Printed Date: 12.Aug.2020 at 05:07
Software Version: Web Wiz Forums 10.16 - http://www.webwizforums.com


Topic: python -c text not correct
Posted By: edward22243
Subject: python -c text not correct
Date Posted: 18.Sep.2019 at 14:07
This is my generator code:

$str = 'python -c "print(''a'');"'
$e = __(external $str read)

It is self-explanatory Smile
The result is that the program crashes: "Unhandled exceptions: Strings only store Characters"

For some other text than a, I get for $e a string of some Chinese signs. 

How to continue?





Replies:
Posted By: edward22243
Date Posted: 18.Sep.2019 at 14:09
Goal was to generate a timestamp as such:

external 'python -c "from datetime import datetime; n = datetime.now(); print(n.strftime(''%d-%b-%H-%M-%S''));"' read 

and that also crashed, hence the investigation.


Posted By: ForumDBA
Date Posted: 18.Sep.2019 at 16:22
The python command isn't using the expected encoding for a command-line command, hence why MetaEdit+ shows an error (it shouldn't actually crash though - it just shows the error and you can press Terminate).

See if there are any options in python to change the encoding to match the command line's Unicode "cmd /u" (UCS-2 le). E.g.  https://stackoverflow.com/questions/492483/setting-the-correct-encoding-when-piping-stdout-in-python" rel="nofollow - https://stackoverflow.com/questions/492483/setting-the-correct-encoding-when-piping-stdout-in-python . If you can't figure it out on the Python side of things, you can simply have python write to a file with external...executeBlocking and then MetaEdit+ can read the file, specifying the encoding if necessary.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 10.16 - http://www.webwizforums.com
Copyright ©2001-2013 Web Wiz Ltd. - http://www.webwiz.co.uk