2013-08-02 25 views
0

我創建了一個需要輸入(通過scanf)的c程序。然後,我創建了.so文件並在python腳本中調用該文件,以便在運行腳本時在終端中輸入輸入內容。但是當我運行python程序時,終端掛起。使用pyqt輸入到.c文件

請注意
1.我的C代碼

#include <stdio.h> 
#include <string.h> 
int open(void) 
{ 
    char input[20]; 
    scanf("input = %s\n",&input); 
    printf("\n%s\n","input"); 
} 

2.命令我使用的編譯代碼

gcc -c usb_comm.c 

3.Creating .so文件

gcc -shared -o libhello.so usb_comm.o 

4. pytho的相關部分n項目
載入.so文件

from ctypes import cdll 
mydll = cdll.LoadLibrary('/home/vineeshvs/Dropbox/wel/workspace/Atmel/libhello.so') 


調用在C程序中定義的聆聽:)

+0

您可能需要閱讀有關['subprocess'模塊(HTTP://docs.python。 org/2/library/subprocess.html),尤其是它的['Popen'類](http://docs.python.org/2/library/subprocess.html#popen-constructor)。然後重新創建你的C模塊作爲一個普通的程序。 –

回答

0

mydll.open()調用scanf函數

mydll.scanf("%c",mydll.open()) 

感謝功能。你爲什麼在Python中調用scanf?

就叫只有mydll.open()

mydll.open() 

UPDATE

#include <stdio.h> 

void open(void) 
{ 
    char input[20]; 
    printf("input = "); // If you want prompt 
    scanf("%s", input); 
    printf("\n%s\n", input); 
} 
+0

我用'mdll.open()'替換了'mydll.scanf(「%c」,mydll.open())''行。但終端仍然掛起,並沒有要求輸入 – vineeshvs

+0

@vineeshvs,你對scanf有誤解。 scanf不會提示用戶。 – falsetru

+0

那麼你會建議從用戶那裏得到哪些輸入? – vineeshvs