1

i hope you guys can help me with this problem because i'm really stuck... I'm trying to execute a program from python and, for some reason, it doesn't work. The script is located at:

path/to/teqc

I've added this line to the .bashrc file:

alias teqc='path/to/teqc'

and, when i run

teqc -tr d input >output

on a terminal it works fine... but, if i run it on a python program, it shows:

sh: teqc: command not found

the code i've been using on python is:

os.system('teqc -tr d input >output')

I tried using

subprocess.Popen('teqc -tr d input >output', shell=True, executable="/bin/bash")

but the only result was to change the error message to

/bin/bash: teqc: command not found

Any help would be really appreciated :)

P.D. I forgot to specify, the operating system is Fedora 21

  • `/path/to/teqc` might not be the same as `path/to/teqc`. Is this a typo in your question? – Isaac Jan 14 '15 at 20:29
  • You could just add `/path/to` to your `PATH` variable, which may (or may not) be more elegant. – ShellFish Jan 14 '15 at 20:30
  • @Isaac Yes, sorry about that. It's just a typo. – Nicolás Godoy Jan 14 '15 at 21:15
  • @VHarisop I read that question before posting but it didn't help me – Nicolás Godoy Jan 14 '15 at 21:21
  • @ShellFish The program has to be able to run on any computer, so I prefer not to modify more files than necessary on my machine – Nicolás Godoy Jan 14 '15 at 21:22
  • @NicolásGodoy Adding something to `PATH` doesn't require you to edit anything more than `.bashrc` which you're already editing. You just delete the alias and add `export PATH="$PATH:/path/to/scripts"`. Also make sure when the script gets called, the correct user is process owner, otherwise the `.bashrc` read will be a different one. – ShellFish Jan 14 '15 at 21:33
  • 1
    `os.system()` most likely cares nothing about any aliases you've set... Try putting the full path in instead of just the program name. Alternatively, make sure that your `PATH` contains `path/to` so that the program can be found when the shell searches for it... – twalberg Jan 14 '15 at 22:02

2 Answers2

2

I would suggest creating a symbolic link to your program .

ln -s /path/to/teqc /usr/bin/teqc
Alexander
  • 12,424
  • 5
  • 59
  • 76
0

I think the problem is that the environment variable PATH is not the same when you run the command in the code using subprocess.

  1. One solution would be to have a soft link in as suggested in the previous answer
  2. Other thing you can do is to have your code set the environment before you execute your command using subprocess the os module comes has a os.environ dictionary which can be used to append the path using something like this

    import os
    import subprocess
    os.environ['PATH'] += ":/path/to/teqc"
    subprocess.Popen(['teqc -tr d input'],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
    
cmidi
  • 1,880
  • 3
  • 20
  • 35