LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c++ calling bash? (https://www.linuxquestions.org/questions/programming-9/c-calling-bash-32391/)

adam_boz 10-09-2002 10:25 PM

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.

Mara 10-10-2002 01:43 PM

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.

jtshaw 10-11-2002 04:52 PM

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).

Azrael 10-12-2002 09:44 AM

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++.

NGraphiX 10-23-2002 12:23 PM

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


All times are GMT -5. The time now is 04:39 AM.