LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Calling shell script from a C program (https://www.linuxquestions.org/questions/linux-newbie-8/calling-shell-script-from-a-c-program-4175518548/)

AsRay 09-14-2014 10:16 AM

Calling shell script from a C program
 
hi,
im COMPLETELY new to linux. using it for the first time. i need to learn how to call a shell script from a c program. the script im using is

#!/bin/bash
# first script
who am i
date
pwd

how do i call it in a c program using 'system'.

Thanks.

TB0ne 09-14-2014 11:23 AM

Quote:

Originally Posted by AsRay (Post 5237722)
hi,
im COMPLETELY new to linux. using it for the first time. i need to learn how to call a shell script from a c program. the script im using is

#!/bin/bash
# first script
who am i
date
pwd

how do i call it in a c program using 'system'.

Not sure what/why you're asking...you seem to answer your own question. You call it using the 'system' function, like you said. Doing it on Linux is no different than calling a program on Windows or Mac in C.

AsRay 09-14-2014 11:45 AM

Im asking what arguments system() takes? im providing the path of the script file but it doesnt work.

the shell script runs fine. the c program compiles. but when i run it it gives me error

sh:1 home/user/documents/firstshell.sh not found.

Could you guide me where i could be wrong?

AsRay 09-14-2014 12:04 PM

Thanks, it was just a syntax error :)

btmiller 09-14-2014 01:06 PM

I'm guessing that you forgot the leading slash before "home" -- am I right?

Note that if you want to be able to actually use the output of the script in the program, you'll need to use something like popen to do so.


All times are GMT -5. The time now is 03:55 AM.