3

I have a compiled binary for Linked list written in c. I placed the executable in /usr/bin/ as /usr/bin/app where app is the name of the executable. This was compiled using gcc.

Can anyone help me to invoke this (app) using a python script.

I have written a script below to do this but seems to give errors. I am very new to python and have very basic knowledge on this. I am just exploring pythons features.

Below is the script code:

#!/usr/bin/env python

import subprocess
proc = subprocess.Popen(['\usr\bin\app'],
                            stdin = subprocess.PIPE,
                            stdout = subprocess.PIPE,
                            stderr = subprocess.PIPE
                        )

(out, err) = proc.communicate()
print out

Here are the errors:

Traceback (most recent call last):
  File "./LinkedList.py", line 7, in <module>
    stderr = subprocess.PIPE
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Thank you for your assistancce

4
  • 3
    Use forward slash: '/usr/bin/app' Commented Aug 30, 2013 at 9:01
  • 1
    '\usr\bin\app' --> \usinpp, as falsetru mentioned use forward slashes. Commented Aug 30, 2013 at 9:04
  • +1 perfect (tagging + effort) in your first question. Commented Aug 30, 2013 at 9:05
  • you may use ctypes for directly using your linked list library with python, or may use cpython to invoke python from the other side i wrote an article on this topic, you may like it huseyinalb.com/2013/04/10/using-python-and-c-together Commented Aug 30, 2013 at 9:08

1 Answer 1

3

Per Comments the answer was:

Use forward slashes '/usr/bin/app'

Personally though I would strongly consider using os.path.join or str.join and os.sep so you don't have to remember which way the slashes should go.

http://docs.python.org/2/library/os.html
http://docs.python.org/2/library/os.path.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.