Assign a bash command result in a Cheetah variable

334 Views Asked by At

I'm currently trying to put the result of a bash command into a Cheetah variable :

#set $name = #echo '$input.element_identifier' + ".phy" | cut -d _ -f 1

'$input.element_identifier' Being (sort of) a link to the name of a previous input file (I try to do that in the section of a xml wrapper for Galaxy, a bioinformatics software)

My problem is that Cheetah does not recognize the '$' in the echo command ... I've tried a lot of other syntaxes but the problem remains the same (so I can't know if the rest of the command is correct)

This is a rather specific question (linked to the administration and use of the Galaxy software), I hope I'm clear.

Thanks

1

There are 1 best solutions below

5
phd On

Two mistakes with your current approach:

  1. #echo doesn't execute OS commands, #echo executes Python expressions.

  2. #echo doesn't return result, #echo puts the result into the output stream (HTML or whatever the output is).

To execute an OS command you need os.system() or subprocess.Popen(). To assign the result of the command you certainly need to catch command's stdout, Popen suites the task better.

Something like that:

#import subprocess
#set $name = $subprocess.check_output($input.element_identifier + '.phy | cut -d _ -f 1', shell=True)