473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Interface with C

I have a program that is developed in C, that has a simple text
interface. I would like to use the same program, but with a GUI. I
would like to use Python to interface with it, so that Python will
simply read and write the code that would be used from a normal user,
but using a TK GUI. For example, in the C program, if you type 0, it
will send a ping. I would like to build a program that will run the C
program, simply inputing the values that the Text interface would
use, but with the graphical interface. EI, the following should work.

-----------
| Ping |
-----------

When this button is hit, it will send a code of 0 to the C program.
Interfacing directly would cause lots of problems, especially whereas
we would like to continue the source of the 2 programs, because
sometimes we have to remotely acess our system, and a text interface
is much better for that than a GUI, but the GUI would be able to give
more functionality. I would prefer a simple interface, perhaps
something like this. BTW, gui.py is the python code, and mcp is the
name of the program.

../mcp | python gui.py

I've forgotten the correct naming to this, but, that's what I would
want, or perhaps it would need to be reversed. Is there a way to do
this with Python, to be able to read the output of the mcp program,
and to send data to it, as if it were just a person at the computer
converting? Thanks!

Sep 14 '05 #1
1 1503
When this button is hit, it will send a code of 0 to the C
program.

./mcp | python gui.py
Your pipe is backwards. Try this:
python gui.py | ./mcp

When your gui.py notices that a button got hit, it can just print the
number 0 (followed by a newline character) to standard output. This
becomes the input to ./mcp, which responds by sending a ping.

Of course, this only works if gui.py does not need to see the output of
../mcp
Is there a way to do this with Python, to be able
to read the output of the mcp program, and to
send data to it, as if it were just a person at the
computer converting?


Ouch, so you need two way interaction. Are you sure about this? Will
your gui program need to change its behavior based on the output of
mcp? If so, then the simple interface offered by pipes is no longer an
option. You will need to call mcp from within your script. To see how
this sort of thing is done, study the following short script:

# mimics the following shell command:
# debug\curve-fit <input.txt >output.txt

import os

inputfilename = 'input.txt'
outputfilename = 'output.txt'

inputfile = open(inputfilename,'r')
outputfile = open(outputfilename,'w')
inputstream,outputstream = os.popen2("debug\\curve-fit")
inputstream.write(inputfile.read())
inputfile.close()
inputstream.close()
outputfile.write(outputstream.read())
outputstream.close()
outputfile.close()

Sep 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
4
by: Doug | last post by:
I am working on an existing .NET (C Sharp) component that had a com interface that was used by a VB component. When it was originally written, it had the SSEAssemblyCom class below - minus the two...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
8
by: rn5a | last post by:
Suppose I have the following class code: Imports System Imports System.Data Imports System.Data.SqlClient Public Class DBSettings Private sqlCmd As SqlCommand Private sqlConn As...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.