vol*_*ing 3 c python user-interface integrate
I have a c console app which converts a c file to a html file, the c file location is passed to the program as a command line argument.(the app is for the windows platform)
What I would like to do is have a python gui app to allow the user to select a file and pass the location of the file to the c app for processing.
I already know how to create a basic python gui with tkinter, but I can't figure out or find any usefull info on how I would go about intgrating the two programs.
Maybe its possible to pipe the string to the c app with the pOpen() method? (but I can't figure out how...)
Note: Im new to python so code examples might be helpful rather then just description, (as Im not familiar with all of the python libraries etc,) although any help at all would be appreciated.
Cra*_*ast 10
您可能想要子进程模块.
至少:
import subprocess
retcode = subprocess.call(["/path/to/myCprogram", "/path/to/file.c"])
if retcode == 0:
print "success!"
Run Code Online (Sandbox Code Playgroud)
这将使用参数运行程序,然后返回其返回代码.
请注意,subprocess.call将阻塞,直到程序完成,因此如果它不是快速运行的那个,那么整个Tkinter GUI将停止重绘,直到它完成.
如需更高级的使用,您可能需要使用subprocess.Popen.这将要求您在命令完成之前进行轮询,但允许您以较少的阻塞进行轮询.
如果您的C程序将HTML打印到标准输出,您将需要像这样管道输出:
proc = subprocess.Popen(["/path/to/myCprogram", "/path/to/file.c"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err_output = proc.communicate()
# output will now contain the stdout of the program in a string
Run Code Online (Sandbox Code Playgroud)