I have two scripts, a shell script with a single line of the form:
and a python script that makes some preprocesing transformation on the text file for this executable.
I would like to "combine" these two tools into a single one. For instance, a python script that makes the shell call at the end. If this one were the best way to do it, how to implement the above shell call in python?
Perhaps make the python script do what it wants to do, save the result to a temp file, and invoke the command on that temp file? Or just make it two independent scripts; if the executable accepts standard input then you can do the good old "python yourscript.py $DOC | executable". In any case make it something that doesn't depend on medit, except for the $DOC part; you don't want to write (and debug!) some complicated stuff in that tiny preferences dialog entry.
You can use subprocess module to invoke the command from python code: https://docs.python.org/2/library/subprocess.html#
Actually I have these scripts in tool files. No, the executable does not seem to accept standard input. I will study the option of using the subprocess module. Does it require "loading" the module? I guess a line like:
as I have seen in some contributed tool code.
I am experimenting with the subprocess module. For instance these lines in the python console open the executable:
>>> import subprocess
where m18 is a script in the path that opens the executable (passing it arguments). The problem now is how to pass the $DOC. As I would have expected, this way does not work:
>>> subprocess.call("m18"+" $DOC",shell=True)
Meaning that the executable opens as if no file argument was passed. I understand it as $DOC not being replaced within the string. Certainly, using the explicit qualified file name instead, does work.
So, how to pass $DOC so that it is replaced by the file name?
In python, $DOC becomes doc, and it's a document object (moo.Edit). You want something like
OK, thank you. It works in this variation:
subprocess.call("m18 "+ doc.get_filename(),shell=True)
But not in the bracket form. I guess that there is a difference in the way the statement is parsed.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.