# How to include shell script in C program

**URL:** <https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216>\
**Category:** Programming\
**Created:** [July 12, 2006, 7:13am UTC](https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216 "2006-07-12T07:13:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mridula](https://community.unix.com/letter_avatar/mridula/32/6_449c533f586939b6e5f246632a46421f.png) [@mridula](https://community.unix.com/u/mridula)\
**Post date:** [July 12, 2006, 7:13am UTC](https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216/1 "2006-07-12T07:13:29Z")

</div>

hi

I want to call a shell script in C program  
the script is : ssh -t user@remote sh /\<remote\>home/user/\<file\_name\>.sh  
and other several commands

C program : Call this script and the retrive the task that is been done in \<file\_name\>.sh file

can any one tell me how to call the script

thankx

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [July 12, 2006, 10:35am UTC](https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216/2 "2006-07-12T10:35:28Z")

</div>

What do you mean by 'retrieve the task'?

---

<div class="post-metadata">

**Author:** ![mridula](https://community.unix.com/letter_avatar/mridula/32/6_449c533f586939b6e5f246632a46421f.png) [@mridula](https://community.unix.com/u/mridula)\
**Post date:** [July 12, 2006, 10:38am UTC](https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216/3 "2006-07-12T10:38:27Z")

</div>

i am retriving some file that are generated by the shell script \<which is running on remote machine\> to my own machine from where i am executing the .c file

---

<div class="post-metadata">

**Author:** ![blowtorch](https://community.unix.com/user_avatar/community.unix.com/blowtorch/32/136_2.png) [@blowtorch](https://community.unix.com/u/blowtorch)\
**Post date:** [July 12, 2006, 9:57pm UTC](https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216/4 "2006-07-12T21:57:26Z")

</div>

So have you been able to execute the script remotely yet? You can do it via the system() call. Try something like this:

```nohighlight
system("ssh -t user@remote sh /<remote>home/user/<file_name>.sh");
system("scp user@remote:/path/to/remote_file /path/to/local_file");

```

If you are being allowed to use system(), then that's all that is there to it. If not, you will have to fork and exec.

---

<div class="post-metadata">

**Author:** ![bhakti](https://community.unix.com/letter_avatar/bhakti/32/6_449c533f586939b6e5f246632a46421f.png) [@bhakti](https://community.unix.com/u/bhakti)\
**Post date:** [July 14, 2006, 12:43am UTC](https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216/5 "2006-07-14T00:43:55Z")

</div>

thanks it works

---

<div class="post-metadata">

**Author:** ![susheel](https://community.unix.com/letter_avatar/susheel/32/6_449c533f586939b6e5f246632a46421f.png) [@susheel](https://community.unix.com/u/susheel)\
**Post date:** [July 30, 2006, 3:13am UTC](https://community.unix.com/t/how-to-include-shell-script-in-c-program/163216/6 "2006-07-30T03:13:03Z")

</div>

thanks for the info....
