Calling SHELL script from C program

Hi,
I just tried to call a simple script from a pretty simple C program. I could not succeed :frowning: a message was thrown saying

"sh: line 1: "Script name with path": Permission denied"

The C program and shell script are below, both are in the same directory and shell script is given full permission (chmod 777).

C Program :

#include <stdio.h>
#include <stdlib.h>

int main()
{
char script[10] = {'s','t','a','t','u','s'};
printf("\nWelcome to the new world :slight_smile: ....\n");
system(script);
}

Shell Script : Name is "status"

clear
echo "sending mail ."

Let me know where the problem is. Thanks in advance

Regards,
Chanakya

  1. You don't have a null terminator on your string in the C program.

  2. You don't have "#!/bin/sh" at the start of your script.

Hi Porter,
Thanks for your quick reply but after adding #!/bin/bash also same error..

Try the following

int i;

i=system("which status"); printf("i=%d\n",i);
i=system("status"); printf("i=%d\n",i);
i=system("./status"); printf("i=%d\n",i);

and while you are at it, post the result of

ls -ld status

Make sure your "staus" scripts should have execute permission as well as give the full path for system lib function
system(/your/path/staus)

Thanks a lor porter .... it WORKED !!!!!!!!! but here i just want to know why you asked me to check for "ls -ld status" ..

Sanjay,
I have already mentioned that status has execution permission..

-Chanakya

Although you now say it worked, we don't know what you did. We're working blind here.

Porter,
I mean it worked with the code posted by you.

-Chanakya