LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-09-2002, 11:25 PM   #1
Registered: Jul 2002
Location: Santa Cruz, CA
Distribution: lfs
Posts: 538

Rep: Reputation: 30
c++ calling bash?

Hi all. I am pretty new to programming as a whole... in my first c++ class and have done a little playing around in bash. My question is this:

I have written a bash script to install a bunch of packages (automated linux from scratch). The code was relatively simple, but the problem I have is that you have to do a "chroot" and "login" a couple of times, which gives you a new bash prompt.... you're not in the program any more. I was wondering if I could write a c++ program which will call the bash scripts (one for each new login) and let me make the program run through w/ out the user needing to call another script.

Is there a way to do this? or would it be better to make it purely c++? if so, how would I use c++ to do system stuff (bash operations)?

I did read that other thread here, but I don't think that it's the same problem I have (if it is, I don't understand it).

Any help would be great. Thank you.
Old 10-10-2002, 02:43 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,547

Rep: Reputation: 160Reputation: 160
You can run every system command (with or without parameters) using system function. I don't know if it fits your needs, but you can read more about it when you run
man system.
Old 10-11-2002, 05:52 PM   #3
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Also check out the fork function (man fork) as it will allow you to spawn a process you don't have to wait for... And the exec functions are also sometimes helpful for executing things (man exec).
Old 10-12-2002, 10:44 AM   #4
Registered: Sep 2002
Location: Germany
Distribution: SuSE 8.0
Posts: 96

Rep: Reputation: 15
Do some housekeeping stuff within the bash skript. Modify your skript that it writes a message into a log file before executing a command, which will give you a new prompt. Then, change the file .bashrc to restart your skript, which should now parse the log file and jump to the part where it last time was exited.

I think this will be easier than using c++.
Old 10-23-2002, 01:23 PM   #5
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154

Rep: Reputation: 30
thanX Azrael sounds like a good idea
I'll try and see what I can up with.


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
Who-is-calling-Who (bash programming) kaone Programming 2 09-19-2005 11:31 AM
bash script calling mplayer afrodocter Programming 13 08-23-2005 11:41 AM
Calling all bash fans.... jong357 Slackware 2 03-16-2004 08:52 PM
Bug in c code calling bash code Linh Programming 11 08-12-2003 05:27 AM
Calling long BASH code within a C program Linh Programming 4 06-24-2003 02:41 PM

All times are GMT -5. The time now is 10:06 PM.

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