![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Apr 2006
Posts: 3
Rep Power: 0
![]() |
how do I call a bash script in C?
Hi,
I'm new to learning C and just wondered if theres a way I can run a bash script from a C program (so that if a certain option is selected eg with switch case then a bash script runs)? thanks ![]() |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You don't mention your OS/Platform. Since that's where these things get done, it would seem to be appropriate. Come back with that info. Meantime, read the forum's rules/FAQ and the "How to Post...." thread.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>You don't mention your OS/Platform.
I think I'll go out on a limb and say that it's a POSIX compliant platform. ![]() >just wondered if theres a way I can run a bash script from a C program Yes, there is. Generally, if you ask a question along the lines of "Can C do <so and so>", the answer is almost definitely "Yes!".
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
ROFL! My mental (if I may loosely define it as that) translation was 'shell/batch script' :o . My apologies to the OP.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 | |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,193
Rep Power: 5
![]() |
Quote:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Apr 2006
Posts: 3
Rep Power: 0
![]() |
Hey,
OS is vector linux. sorry I dont think I explained the question very well, I want to open a bash script (.sh file) I've already written within a C program so that partway through the program it also runs the bash script. Narue - the question was more HOW can c do so and so! ![]() thanks ![]() |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Apr 2006
Posts: 3
Rep Power: 0
![]() |
actually system () works fine for what i'm trying to do with it, thanks very much
![]() |
|
|
|
|
|
#8 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>Narue - the question was more HOW can c do so and so!
I know, but you'll find that programmers tend to be smartasses. If you unintentionally ask a yes or no question, you're damned sure to get a yes or no answer from at least one person. ![]()
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
man popen
man system man exec All of these man pages explain one way to do what you ask. Use popen if you want to get output - like stderr. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|