Calling SHELL script from C program


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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 :-( 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 :-) ....\n");
system(script);
}


Shell Script : Name is "status"

clear
echo "sending mail ."


Let me know where the problem is. Thanks in advance

Regards,
Chanakya
# 2  
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.
# 3  
Hi Porter,
Thanks for your quick reply but after adding #!/bin/bash also same error..
# 4  
Try the following

Code:
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

Code:
ls -ld status

# 5  
Hammer & Screwdriver Some info

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

~~~Sanjay~~~
# 6  
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
# 7  
Quote:
Originally Posted by Chanakya.m
i just want to know why you asked me to check for "ls -ld status" ..
Although you now say it worked, we don't know what you did. We're working blind here.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #207
Difficulty: Easy
Open Shortest Path First (OSPF) is a routing protocol for Internet Protocol (IP) networks which uses a link state routing (LSR) algorithm.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass the environment name while calling java program from unix script?

Hi, I'm trying to test one unix shell script in dev environment. But I'm not sure how to pass the environment in my java program calling code. I'm trying to use -DconsumerEnv="DEV" but unfortunately I get 'null' while trying to print the value from java class. System.out.println("Environment: "+... (4 Replies)
Discussion started by: Pramit
4 Replies

2. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

3. Shell Programming and Scripting

Calling perl script in shell program

How to call a perl script in shell program / shell scripting. PLS HELP ME (2 Replies)
Discussion started by: hravisankar
2 Replies

4. Programming

Calling a shell script from a C program

Hi, I have a shell script which connects to a database and fetches the count of the records from a table. I want to embed this whole script in a C program. Also the count fetched should be available in the C program for further usage. Please let me know how this can be done. Thanks (9 Replies)
Discussion started by: swasid
9 Replies

5. Shell Programming and Scripting

Calling a shell script from a C program

Hi, I have a shell script which connects to a database and fetches the count of the records from a table. I want to embed this whole script in a C program. Also the count fetched should be available in the C program for further usage. Please let me know how this can be done. Thanks ... (0 Replies)
Discussion started by: swasid
0 Replies

6. UNIX for Dummies Questions & Answers

Calling a c program using perl script

On bash I run precompiled c Program as follows: ./create_cust 1 10000 US S > us_cust.csv create_cust is a c program and requires 4 parameters. I am redirecting the output of this program to csv file I need to run this same program in perl I am aware of exec command though not... (7 Replies)
Discussion started by: gkbond
7 Replies

7. Shell Programming and Scripting

Run shell script from C program by calling fork and execl

I need to write a c program that uses the fork and excel system calls to run the shell script mode invoked like this: "./mode 644 ls -l" (that is the argumetns will always be 644 ls -l) here's the mode script: #!/bin/sh octal="$1" shift find . -maxdepth 1 -perm $octal -exec $@ {} \; ... (3 Replies)
Discussion started by: computethis
3 Replies

8. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

9. Shell Programming and Scripting

calling a program (w/ params) from within shell

Hi all, I need to call some script (s1) from within my shell script (s2). s1 accepts parameters and I want to feed it with values of params from my script. I tried many things but none work (I am so much of a beginner), please help one of my attempts : . . . param1="hehe" param2="haha" ... (12 Replies)
Discussion started by: Lorna
12 Replies

10. Shell Programming and Scripting

Calling Functions of Other K Shell Program

Hi, I have a K shell a.ksh function abc { // Some logic } In b.ksh i have included the a.ksh ./a.ksh I want to call the abc function from this b.ksh script. Thanks Vijay (2 Replies)
Discussion started by: vijaykrc
2 Replies

Featured Tech Videos