0

So, I have an external application which I put it in my /opt/app/bin/thisapp directory. The application can be executed via command line and will give output to stdout. I add /opt/app/bin/ to my environment variable. Basically, I can call thisapp in my terminal and produce an output.

I am trying to call this application inside a python and capture its output inside python. This is my script (really simple):

from subprocess import call
call(["thisapp"])

It ressults in an error

OSError: [Errno 13] Permission denied

I already make sure to chmod 777 -R in the directory but still same. Then I am trying to call the absolute path of this app which is:

call(["/opt/app/bin/thisapp"])

This time, the error is:

OSError: [Errno 2] No such file or directory

Can anyone suggest what should I do? I am really new to python.

Bharata
  • 685
  • 3
  • 11
  • 23
  • Are you really *really* sure that the full path to the program is `/opt/app/bin/thisapp`? What if you do `sudo chmod +x path/to/app` to make it executable? – jDo May 06 '16 at 01:41
  • I already make sure calling this via terminal. That's why it is weird and it is already executable. – Bharata May 06 '16 at 01:44
  • What if you copy the program to your home folder and try to run it via python again? What if you do `import sys; sys.path.append("/opt/app/bin/")`? Does `which thisapp` in terminal show the full path you're specifying in python? – jDo May 06 '16 at 01:50
  • I copy the script to my python directory, same as my python script. In terminal I tried calling it via ./thisapp and it is success. Via python, I call it: call(["./thisapp"]) It is still not working. The error is no such file or directory. I tried the import sys still not working. – Bharata May 06 '16 at 01:59
  • I add shell=TRUE and it is working! – Bharata May 06 '16 at 02:02
  • Ok, `shell=True` can be a security risk though - best to avoid it if you can. Check [this](https://www.reddit.com/r/Python/comments/2tzljx/shelltrue_with_subprocess_methods/) and [this](https://stackoverflow.com/questions/25465700/python-subprocess-call-with-shell-false-not-working). I think there's either still something wrong with your path environment variables (and therefore the path you're specifying isn't found) or maybe you're passing arguments to `thisapp` but haven't mentioned it. – jDo May 06 '16 at 02:11
  • Oh, I noticed that I used another parameter in my call earlier. I call the app call("thisapp param1"). So, should I split into : call(["thisapp","param1"])? If I have more than 2 params, should I call this : call(["thisapp","param1","param2"])? – Bharata May 06 '16 at 02:14
  • There are parameters?! You should mention that! You write `call(["/opt/app/bin/thisapp"])` in your question and but now you mention parameters? Why didn't you add that to the question? – jDo May 06 '16 at 02:16
  • My bad, because when I check the existence of file I use parameter and I just copy and paste to the script. So, I don't realize parameter si the problem. – Bharata May 06 '16 at 02:19
  • `subprocess.call(["/opt/bin/app/thisapp", "param1", "param2", "param ..."])` – jDo May 06 '16 at 02:21
  • 1
    Ok, it is working now and great. Already start processing the output. Thank you very much. Just first day writing Python script. – Bharata May 06 '16 at 02:25
  • Cool, you're welcome! – jDo May 06 '16 at 02:28

0 Answers0