I would like to ask you a question in unix - c
and a shell script. I will just explain you
the situation where i got the problem.
I have tried to replicate the word count wc
command in shell script. There i was able to
calculate the number of lines in a file and
the number of words in a file but i was not
able to manipulate the number of characters.
So i planned to call a c program and calculate
the number of characters in that program and
return the value back to the shell. I dont
know to proceed.
If you could help me solve this problem ??
I repeat the question in precise
HOW CAN WE MAKE A SHELL SCRIPT AND A C PROGRAM
TO COMMUNICATE ??
1. how to call a c program from script ?
I have to pass values to c program and get back
value from that program?
2. how a shell script can be called from a c program?
I am working with Red Hat linux 7.1
>how to call a c program from script ?
Compile the C program to executable and just write the name of the
executable in the script to start it. For example the program wc is also
written originally in C and is compiled to executable. There is no
difference who has written the program.
>I have to pass values to c program
write the parameters after the executable name as command line arguments.
These will appear in the 'main()' function arguments.
>and get back value from that program?
Use back tick to start the program and you will get all values that the
program prints to the standard output.
>how a shell script can be called from a c program?
Use the function 'fork()' and 'exec*()' Please read the documentation on
[ back to toc ]