How to run python scripts using tcl exec command

I have a tcl script driver, which in turn calls several other programs. I want to call a python script from my tcl script. let's say this is my python script "1.py"

#!/usr/bin/python2.4 import os import sys try: fi = open('sample_+_file', 'w') except IOError: print 'Can\'t open file for writing.' sys.exit(0) 

and tcl script - "1.tcl"

 #! /usr/bin/tclsh proc call_python {} { exec python 1.py } 

This does not give any error, but at the same time does not perform the operations present in the python script.

What should replace the exec python 1.py code snippet in 1.tcl to call the python script? Is it possible to call a python script using exec?

Thanks in advance!

+6
source share
1 answer

Your tcl script defines a procedure to execute a python script, but does not call a procedure. Add a call to your tcl script:

 #! /usr/bin/tclsh proc call_python {} { set output [exec python helloWorld.py] puts $output } call_python 

In addition, everything written to stdout by a process launched via exec will not be displayed in your terminal. You will need to grab it from the exec call, and the listing will explicitly point to itself:

 #! /usr/bin/tclsh proc call_python {} { set output [exec python helloWorld.py] puts $output } call_python 
+11
source

Source: https://habr.com/ru/post/893553/


All Articles