LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-14-2014, 10:16 AM   #1
AsRay
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Rep: Reputation: Disabled
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.
 
Old 09-14-2014, 11:23 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,995

Rep: Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327
Quote:
Originally Posted by AsRay View Post
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.
 
Old 09-14-2014, 11:45 AM   #3
AsRay
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
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?
 
Old 09-14-2014, 12:04 PM   #4
AsRay
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks, it was just a syntax error
 
Old 09-14-2014, 01:06 PM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a shell script present on another server using perl script. anandg111 Linux - Server 4 07-18-2012 12:23 AM
[SOLVED] Calling a Shell script from inside a Shell script manyrootsofallevil Programming 7 07-10-2012 04:42 AM
[SOLVED] Help calling a shell script inside a python script WyoChuck Linux - Newbie 4 05-28-2012 09:39 PM
Shell script calling shell script - List of all nikunjbadjatya Programming 7 04-13-2011 06:27 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration