2013-08-30 41 views
3

我有用c編寫的鏈接列表的編譯後二進制文件。我將可執行文件放在/ usr/bin/as/usr/bin/app中,其中app是可執行文件的名稱。這是使用gcc編譯的。如何使用Python調用C可執行文件

任何人都可以幫助我調用這個(應用程序)使用Python腳本。

我已經寫了一個腳本來做到這一點,但似乎給錯誤。我對python很陌生,對此有非常基本的瞭解。我只是在探索pythons功能。

下面是腳本代碼:

#!/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 

下面是錯誤:

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 

感謝您assistancce

+3

使用正斜槓:' '在/ usr/bin中/ app'' – falsetru

+1

'' 的\ usr \ BIN \ app'' - >'\ usinpp',如falsetru提到,在使用正斜槓。 –

+0

+1完美(標記+努力)在你的第一個問題。 –

回答

相關問題