Better understanding of Execute CodeBox Code

Home Forums cherrytree Better understanding of Execute CodeBox Code

Tagged: 

This topic contains 0 replies, has 1 voice, and was last updated by  eureka 4 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #124592

    eureka
    Member

    I would like to have a better understanding of usage of Execute CodeBox Code.
    This experiment below was run in Windows 10.
    I also have CherryTree in Ubuntu 16.04.

    Currently I can Edit > Insert CodeBox in any node.

    I set Automatic Syntax Highlighting on.

    I click on the button under Automatic Syntax Highlighting and choose a code type

    e.g. I choose python instead of sh

    In the CodeBox I write one line of python test code:

    print ("hello world")

    Next I select the CodeBox by left click and then right click > ” Execute CodeBox Code”

    Warning pops up with message

    “Do you want to Execute the Code?”

    I select Yes

    But then the command terminal pops up

    'python2' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Program Files (x86)\CherryTree\bin>

    I have python (2.7) and python (3.6) installed so I deduce that I need a code type which is not python2.

    I try changing CodeBox Properties from python to python3

    I Execute CodeBox Code again.

    'python3' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Program Files (x86)\CherryTree\bin>

    Hmmm.

    So next I go back to Edit > Preferences

    I change …
    python python2 <tmp_src_path>
    to
    python py -2 <tmp_src_path>

    and I change …
    python3 python3 <tmp_src_path>
    to
    py -3 <tmp_src_path>

    Next I try Execute CodeBox Code again
    and this time it works …

    hello world
    
    C:\Program Files (x86)\CherryTree\bin>

    Conclusion: To execute python CodeBox I must use the python wrapper py.exe (py -2 or py -3) instead of python2 python3.

    This is documented here … https://docs.python.org/3/using/windows.html … section 3.4.1.1 from the command line.
    ….

    My next puzzle is getting PowerShell to run an executable binary.

    I create a fresh CodeBox.

    I change CodeBox Properties to powershell.

    I add this line of code into CodeBox.

    ipconfig /all

    I then select CodeBox and right click > ” Execute CodeBox Code”

    I see a warning

    You must associate a command to 'powershell'.
    Do so in the Preferences Dialog

    I go back to Edit > Preferences and add powershell using + button

    powershell REPLACE_ME <tmp_src_path>

    I am not sure what to insert in “REPLACE_ME”

    I guess and edit it to be …

    powershell powershell <tmp_src_path>

    But when I ” Execute CodeBox Code” I find that the command runs but pops up the code content in exec_code Notepad .. instead of executing the CodeBox Code.

    Same question if I try to add html type …

    html REPLACE_ME <tmp_src_path>

    Or add js type …

    js REPLACE_ME <tmp_src_path

    My general question is: what should be placed in REPLACE_ME when adding new element types such as html, js, etc.

    Work around:

    I did think of one way of executing PowerShell and that is to just have a single python 3.6 wrapper to run a PowerShell command as a subprocess.

    Searching around (PowerShell python subprocess) I followed a suggestion in thread here to launch powershell through python subprocess.

    https://stackoverflow.com/questions/42525819/python-execute-powershell-command

    I found that this example works for me when I choose py -3..

    So for now I will use a python script to launch PowerShell. But I still want to understand what to place in REPLACE_ME for powershell, html, js.

    • This topic was modified 4 weeks ago by  eureka.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.