Easiest way to integrate python gui application with c console application

I have a console application c that converts a c file to an html file, the location of the c file is passed to the program as a command line argument (the application is for the Windows platform)

What I would like to do is have a python gui application to allow the user to select a file and pass the file location to application c for processing.

I already know how to create a basic python gui with tkinter, but I cannot find or find any useful information about how I am going to include two programs.

Maybe it is possible to pass a string to application c using the pOpen () method? (but I can't figure out how ...)

Note. I am new to python, so the code examples may be useful, not just a description (since I am not familiar with all python libraries, etc.), although any help will be appreciated at all.

+3
source share
2 answers

You probably need a subprocess module .

Least:

import subprocess
retcode = subprocess.call(["/path/to/myCprogram", "/path/to/file.c"])
if retcode == 0:
   print "success!"

This will start the program with arguments and then return a return code.

Please note that subprocess.call will be blocked until the program ends, so if it does not work quickly, the entire Tkinter GUI will stop redrawing until completion.

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
+10

, , Popen subprocess.

 process = subprocess.Popen(['myutil', file_location]...)
 process.wait()

, PIPE stdout .

+2

Source: https://habr.com/ru/post/1728833/


All Articles