LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-21-2006, 09:19 PM   #1
Ha1f
Member
 
Registered: Jun 2005
Location: University of Maryland
Distribution: FreeBSD
Posts: 268

Rep: Reputation: 30
link c++ and bash?


Hi all,

I'd like to know if this is possible. I'm writing a C++ program that I want to run bash scripts. The thing is, I'd like to be able to take the result of the script and use it as a value in my C++ program. For instance, if the script failed (either because of an error, or because it acheived a value within itself that would return a failure) I'd like the C++ program to be able to take that value and use it. Is this possible? If so, how?

Thanks
 
Old 01-21-2006, 09:54 PM   #2
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
Quote:
Originally Posted by Ha1f
Hi all,

I'd like to know if this is possible. I'm writing a C++ program that I want to run bash scripts. The thing is, I'd like to be able to take the result of the script and use it as a value in my C++ program. For instance, if the script failed (either because of an error, or because it acheived a value within itself that would return a failure) I'd like the C++ program to be able to take that value and use it. Is this possible? If so, how?

Thanks
The easiest way would be to have your bash script emit the information you want from it to standard output or standard error. Then you could just use the normal C++ facilities to read from those streams.

There are other techniques for IPC (inter-process communication), but in *NIX environments, the standard streams are some of the simplest to work with.
 
Old 01-21-2006, 10:50 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
And of course there's always "popen()": it'll read stdout from your script; it'll also read your script's "exit" status: whichever (or both) you prefer.

"man 3 popen", if you're interested.
 
Old 01-22-2006, 07:11 AM   #4
Ha1f
Member
 
Registered: Jun 2005
Location: University of Maryland
Distribution: FreeBSD
Posts: 268

Original Poster
Rep: Reputation: 30
wow--thats awesome.

thanks so much guys!!
 
  


Reply



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
Error in make bash with static-link Kdr Kane Programming 7 02-25-2006 12:53 AM
OpenBSD 3.6 install D-Link 300T / D-Link DFE 528TX lesleyb *BSD 2 04-01-2005 06:29 PM
bash and symbolic link zuma Linux - Newbie 7 01-03-2005 04:18 PM
Checking for a valid HTML link in Bash/Korn? Aziz Programming 1 11-30-2004 04:10 PM
Wake on Lan - Link on b4 power up, No Link light after shutdown? Mark007 Linux - Networking 0 11-20-2004 08:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06: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
Open Source Consulting | Domain Registration