Call a C programming executable inside a C program


 
Thread Tools Search this Thread
Top Forums Programming Call a C programming executable inside a C program
# 1  
Old 01-08-2010
Call a C programming executable inside a C program

hi guys
i have only basic knowledge of C so guys plz help me .....

is C language support call the C executable inside the C ??

example contect mainA.c have a many function define in the struct,when i compile mainA and make a executable the name is ( A ),can i use executable C inside the C <my C program call the executable ( A ) > .


Thankss all ..
# 2  
Old 01-08-2010
Hi,
You can call any other program in the operating system with, for example, system(), and it can call/run itself (ie another instance of itself). But what is it that You want to do? Pass values between them?

/Lakris
# 3  
Old 01-09-2010
sory guys , i don't understand ..

the executable C have a many function , when i use the system(" ") then function name it actually call the exe file to run

what i want is ,
i wanna to call specific function from the executeable file, is there anyway i can do it ?

---------- Post updated at 08:27 AM ---------- Previous update was at 01:49 AM ----------

hai, guys...

the example content mainfile.c :

Code:
struct {
    char namefunction[40] ;
    int (*f)(int argc, char *argv[]) ;
}manyfunction[2] =
{
      {"func1",func1}
      {"func2",func2}
} 

int main (int argc, char *argv[]) {
 /* the code can access to struct match something function from request */

}

when mainfile.c compile to executable,
other source C can call its themself <function in define> ?

can i make a differences executable ?


Thankss..

Last edited by pludi; 01-09-2010 at 09:36 AM.. Reason: code tags, please...
# 4  
Old 01-09-2010
You can't just call a function from an executable. If you want to graba function from a file as a function pointer and execute it, you have to do so from a shared library with the dlopen() series of calls. To compile a shared library instead of an executable file, add the -shared flag (and, on some architectures, -fPIC). See man dlopen.
# 5  
Old 01-11-2010
Quote:
Originally Posted by isnoname
when mainfile.c compile to executable,
other source C can call its themself <function in define> ?

can i make a differences executable ?


Thankss..
Hi again. Your description is still a bit unclear.

You create the two programs Yourself?

If You intend to keep the programs separate maybe You should consider using program arguments, so You can control what function will be called? Or even "call itself" but with an argument to make it run a specific function. You can do that If You want it to run in its own process, instead of calling the function directly from the same process.

/Lakris
# 6  
Old 01-11-2010
Hi!

Look at this document, it should answer many of your questions.
Program Library HOWTO

HTH,
Loïc

Last edited by Loic Domaigne; 01-16-2010 at 01:37 PM.. Reason: remove signature
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Xargs to call python executable to process multiple bam files

I am running the below loop that to process the 3 bam files (which isn't always the case). A .py executable is then called using | xargs sh to further process. If I just run it with echo the output is fine and expected, however when | xargs sh is added I get the error. I tried adding | xargs... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

To see if a program exist and is executable

Hi, I am making a program that needs to detect if the program name in parameter is a valid runable program. But the line if ; then never seem to work. Even if I run like: ./script cat "-u" cat "-u" inputfile Thank you everyone. #!/bin/bash # usage() { #print usage message and quit... (4 Replies)
Discussion started by: leonmerc
4 Replies

3. Programming

Makefile for more than 1 executable program

Can anyone give me a makefile that creates 3 exe?for example, let's suppose i have the following files: blah1.c blah1.h blah2.c blah2.h blah3.c blah3.h i've searched and searched but so far i was not able to complete it. (4 Replies)
Discussion started by: bashuser2
4 Replies

4. Shell Programming and Scripting

Automatically select records from several files and then run a C executable file inside the script

Dear list its my first post and i would like to greet everyone What i would like to do is select records 7 and 11 from each files in a folder then run an executable inside the script for the selected parameters. The file format is something like this 7 100 200 7 100 250 7 100 300 ... (1 Reply)
Discussion started by: Gtolis
1 Replies

5. Programming

how to call c executable inside c program??

hi guys i have only basic knowledge of c so guys plz help me ..... i want 2 call c executable which requires file name as argument and i need to modify file contents before calling that executable now my question is how can i call this c executable inside another c program with arguments ?? i... (9 Replies)
Discussion started by: zedex
9 Replies

6. Shell Programming and Scripting

Unable to call executable from script

Now I am using the HP-UX11.11 version. The scripts are runninh in KSH shell. While I wan to call one executable of any Pro*C file, I have got the following error, however the executable is running fine directly. testpri Started at 10.05.200923:40 /usr/lib/dld.sl: Bad magic number for... (0 Replies)
Discussion started by: priyankak
0 Replies

7. Shell Programming and Scripting

Need to call an Executable (.exe) using shell

Hi all , I need to call an executable (.exe) using shell script. Actual need is i need to call that shell script and do an export of some tables is there any way . the executable is datamover Please let me know if there are any option !! (2 Replies)
Discussion started by: raghav1982
2 Replies

8. Programming

launch an executable from a C++ program

Hi everybody! Could you please tell me how can I launch an executable from a C++ (on unix) program? thanks in advance! (2 Replies)
Discussion started by: nadiamihu
2 Replies

9. Programming

function call in executable

Hi, I want to write a program in C or in Perl which will tell me that a function is called in which executables. I tried to use the unix command like 'nm', 'strings' and so on to find out whether a function is called in that executable or not but could not able to find a clue. The whole... (1 Reply)
Discussion started by: rocky_74
1 Replies

10. Shell Programming and Scripting

calling a C executable from inside a Perl script

here's the Perl code snippet... how can i call my C executable 'porter-stemmer' and pass it $1 as an argument? Thanks for the help! # Read through the original topic set, and modify based on the current # pre-processing options while (<TOPIC_ORIG>) { # Run pre-processing over only the... (3 Replies)
Discussion started by: mark_nsx
3 Replies
Login or Register to Ask a Question