Click to See Complete Forum and Search --> : getting the value of a c function in unix shell script
surjyap
September 27th, 2005, 05:04 AM
Let say there is a module fileselection module written in c language which returns the file name. Is it possible to get the file name from the file selection module directly, I mean can we call a c function directly in shell script without doing executable. If possible then how it can be implemented. If there is any other way to implement the same thing then please let me know. Let me make more clear. consider a shell script fileimport and c function fileselection module. This file selection module returns a file name. i want this file name in my script. how is it possible?
olivthill
September 27th, 2005, 05:22 AM
* The C source code must be compiled (unless you find a C interpreter module (there was once, in the old time on Atari)). This will make an executable file.
* In your program, you can have "exit(n);". This will return a value to the shell. a_value=`my_prog.exe`(N.B. use backquotes).
But the value should be an integer, not a string.
* In your program, you can write data to the standard ouptut (stdout)
/*getfilemane.c */
#include <stdio.h>
...
fprintf(stdout, "%s", a_file_name);
Then, in the shell you can redirect the output to a variable.
gefilemane.exe | read the_filename
echo $the_filename
surjyap
September 27th, 2005, 05:49 AM
But how is it possible to create an executable without main!!!!!!!!!!!!!
olivthill
September 27th, 2005, 06:01 AM
An executable needs an entry point, and with C programs, the entry point is the main function. Is it a problem to have a main function in your program?
surjyap
September 27th, 2005, 07:21 AM
in fact my intent was to do it without main. But waht I belive it is not possible to execute a c function without main.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.