我創建了一個需要輸入(通過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程序中定義的聆聽:)
您可能需要閱讀有關['subprocess'模塊(HTTP://docs.python。 org/2/library/subprocess.html),尤其是它的['Popen'類](http://docs.python.org/2/library/subprocess.html#popen-constructor)。然後重新創建你的C模塊作爲一個普通的程序。 –