954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Returing Value from C++ code to unix shell script

Hi All,

I am working on a situation suppose i am calling one exe(C++ code) from unix shell script now i want that 2 values in that unix script which this c++ code will get from some URL.
Any Idea how can i get those 2 values from C++ code exe to unix shell script.

Thnks
Rohit

RohitSahni
Light Poster
35 posts since Jul 2007
Reputation Points: 25
Solved Threads: 0
 

Write the values to a file from your program.

ofstream outs( "data.txt" );
outs << value1 << "\n" << value2 << std::endl;


Choice of shell matters. Here I usebash and awk.

value1=`awk 'NR==1' data.txt`
value2=`awk 'NR==2' data.txt`


If you want to avoid the file on disk, you can always write tostd::cout and pipe the result into awk. Etc.

Hope this helps.

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You