How to pass variables from C program to wxPython GUI

I’m making a wxPython GUI, the back-end of which is a C program. So, I can pass filenames and other required variables as commandline arguments from the GUI to the program but is it possible to go the other way round? I have some string variables in my C program which I have modified using snprintf. Now, I wish to pass those to the GUI so that they can be saved in a database.

P.S. - Please be kind to answer in detail as I’m a beginner. Thankyou! :slight_smile:

Actually, I call my C program through a shell script which is something like this -

shell-script

cd
cd /home/ubuntu/Documents/aescodes/aes
gcc -c -O2 -fomit-frame-pointer aescrypt.c aeskey.c aestab.c aes_modes.c
ar rcs libaes.a *.o gcc aespro.c libaes.a -o program
./program "$4" "$2"
"$1"

the part of the wxPython code used to call it

proc = subprocess.Popen(['encryption', self.namex, answer1, self.path, self.filePath])
    out, err = proc.communicate()

You have two possible simple answers and two possibly more complex
but more satisfactory ones:

···

On 21/07/14 04:27, Ankita Juneja wrote:

      Actually, I call my C program through a shell script which is

something like this -

shell-script

cd
cd /home/ubuntu/Documents/aescodes/aes
gcc -c -O2 -fomit-frame-pointer aescrypt.c aeskey.c aestab.c aes_modes.c
ar rcs libaes.a *.o gcc aespro.c libaes.a -o program
./program "$4" "$2"
"$1"

the part of the wxPython code used to call it

proc = subprocess.Popen(['encryption', self.namex, answer1, self.path, self.filePath])
    out, err = proc.communicate()

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
  1.     Change your C program or script to print the required
    

information with some sort of marker(s) before each and parse
the value of out from communicate to retrieve them.

  1.     Modify your C program or even your script to save the required
    

information to a fixed, or passed in as a parameter, file, in
your GUI look for an update to that file, read & parse it.

  1. Convert your C to python - this may result in it
    running slower but it will be more portable.
  2.     Modify your code so that you do not need to re-build the C
    

every time and embed the pre-built C as a library/extension in
your python - see the help documents on embedding.
Gadget/Steve

Either have the C program print to stdout or stderr then capture it with the subprocess.communicate call... Or if the C program is relatively simple, use ctypes and use it as a Python module:
http://chimera.labs.oreilly.com/books/1230000000393/ch15.html#_problem_240

An alternative to Ctypes is Cython -- better for tighter connection to the
C code. But either will work fine. On the other hand -- you really don't
want to use the raw CPython API.

-Chris

···

On Mon, Jul 21, 2014 at 8:56 AM, Nathan McCorkle <nmz787@gmail.com> wrote:

Either have the C program print to stdout or stderr then capture it with
the subprocess.communicate call... Or if the C program is relatively
simple, use ctypes and use it as a Python module:
http://chimera.labs.oreilly.com/books/1230000000393/ch15.html#_problem_240

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov