Call C Program From Shell Script

Hi,
Could anybody please let me know how to call a C_Program
from shell script. I know through command "system" we can call
shell script from C program.

Awaiting response.

Thanks and regards,
Chanakya M

use backquotes if you want to capture output from your C program

var=`/path/to/c_prog arg1 arg2`

or

run it like any other command

/path/to/c_prog arg1 arg2

hi yogesh shawant..
i have got many ideas from ur reply s...
i need to write a shell script that will pass two arguments which will call a C program and return the values back to the script..
Please help me out..
eg:- adding 2 number by passing arguments in c program how can i trigger it froom shell script
try giving the full source code for the script..
Thanxs in advance.. :slight_smile:

num1=23
num2=42
result=`/path/to/add $num1 $num2`
echo $result

should give 65 as output

But for something this simple as basic math ops you can use the shell directly

num1=23
num2=42
result=$(( $num1 + $num2 ))
echo $result

Thanx Buddy.
Its working cool :smiley:

1 Like