Glubbdrubb
Glubbdrubb

Reputation: 357

python sh module is not accepting variable as command

I am reading a list of unix command line programs from a file into a list, pList. All of the programs are in my PATH. I then assign one of the entries to a variable: prog.

I would then like to execute that program using the non standard module sh

sh.prog('arguments')

However, sh interprets the name prog literally, and not as a variable containing a string. It looks for the program prog, which doesn't exist. Is there a way around this problem? Would using the subprocess call function have the same problem? How can I get around this?

Upvotes: 0

Views: 73

Answers (1)

glibdud
glibdud

Reputation: 7840

The sh module has a Command class for situations like this.

sh.Command(prog)('arguments')

Upvotes: 1

Related Questions