17 November 2017 at 18:07 #124592
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>
So next I go back to Edit > Preferences
I change …
python python2 <tmp_src_path>
python py -2 <tmp_src_path>
and I change …
python3 python3 <tmp_src_path>
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 184.108.40.206 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.
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.
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.
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 8 months ago by eureka.
You must be logged in to reply to this topic.