Support LQ: Use code LQ3 and save \$3 on Domain Registration
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Pass the output of a shell script to c++ program
 Linux - Newbie This Linux forum is for members that are new to Linux. Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

08-19-2013, 01:56 PM   #16
TB0ne
LQ Guru

Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,117

Rep:

Quote:
 Originally Posted by samasara My c++ code is a code that assess risk based on fuzzy logic. I used a fuzzylogic library and then write such a code. my code is like this: Code: ```#include #include #include "../FuzzyRule.h" #include "../FuzzyComposition.h" #include "../Fuzzy.h" #include "../FuzzyRuleConsequent.h" #include "../FuzzyOutput.h" #include "../FuzzyInput.h" #include "../FuzzyIO.h" #include "../FuzzySet.h" #include "../FuzzyRuleAntecedent.h" using namespace std; int main(){ int Acc, Get, Third; Fuzzy* fuzzy = new Fuzzy(); // Step 2 - Creating FuzzyInputs FuzzyInput* Threat = new FuzzyInput(1); FuzzySet* lowThreat = new FuzzySet(0, 1.875, 1.875, 3.75); Threat->addFuzzySet(lowThreat); //add fuzzy set low to threat level FuzzySet* mediumThreat = new FuzzySet( 3.125, 5, 5, 6.875); // other fuzzyset will be made like this i do not write them here just for making the code shorten. FuzzyOutput* Risk = new FuzzyOutput(1); FuzzySet* lowRisk = new FuzzySet(0, 1.875, 1.875, 3.75); Risk->addFuzzySet(lowRisk); //Step 3:Creating fuzzy rules //for example: 1. If (Threatlevel is Low) and (vulnerability is Low) and (Asset_value is High) then (Risk is Low) FuzzyRuleAntecedent* ThreatlowThreatAndVulnerabilitylowVulnerability = new FuzzyRuleAntecedent(); ThreatlowThreatAndVulnerabilitylowVulnerability->joinWithAND(lowThreat, lowVulnerability); FuzzyRuleAntecedent* AssethighAsset = new FuzzyRuleAntecedent(); AssethighAsset->joinSingle(highAsset); FuzzyRuleAntecedent* ifThreatlowThreatAndVulnerabilitylowVulnerabilityAndAssethighAsset = new FuzzyRuleAntecedent(); ifThreatlowThreatAndVulnerabilitylowVulnerabilityAndAssethighAsset->joinWithAND(ThreatlowThreatAndVulnerabilitylowVulnerability, AssethighAsset); FuzzyRuleConsequent* thenRisklowRisk = new FuzzyRuleConsequent(); thenRisklowRisk->addOutput(lowRisk); FuzzyRule* fuzzyRule1 = new FuzzyRule(1, ifThreatlowThreatAndVulnerabilitylowVulnerabilityAndAssethighAsset, thenRisklowRisk); fuzzy->addFuzzyRule(fuzzyRule1); fuzzy->setInput(1,Acc); fuzzy->setInput(2,Get); fuzzy->setInput(3,Third); fuzzy->fuzzify(); cout << "Threat:" << lowThreat->getPertinence() << ", " << mediumThreat->getPertinence() << ", " << highThreat->getPertinence() << endl; cout << "Vulnerability:" << lowVulnerability->getPertinence() << ", " << highVulnerability->getPertinence() << ", " << endl; cout << "Asset:" << lowAsset->getPertinence() << ", " << highAsset->getPertinence() << endl; float output1 = fuzzy->defuzzify(1); cout << "Risk:" << output1 << endl; return 0;``` As you can see 3 variables Acc, Get ,Third should be feed from a shell script that is like this:
Go back and read the tutorial on C++ and how to get command-line parameters that was looked up and GIVEN to you. Apply that to your C++ code. Again, we are not going to write your code for you a second time. Firerat pointed out what needed to be done, and you're obviously using some sort of library system that's referred to in your C++ code as "../". Is that a valid path?

08-19-2013, 02:03 PM   #17
samasara
Member

Registered: Aug 2013
Posts: 34

Original Poster
Rep:
Pass the output of a shell script to c++ program Reply to Thread

Quote:
 Originally Posted by Firerat @samasara your c++ code does not have a single cin, your Acc, Get and Third are all null.. You need to learn c/c++ , I'm not going to do it for you and regards the 'errors' It looks to me like you are running your fuzzycode2.cpp source file as if it were a shell script! look, the code you posted.. Code: ```sh FuzzyLogic.cpp FuzzyLogic.cpp: line 13: using: command not found FuzzyLogic.cpp: line 14: syntax error near unexpected token `(' FuzzyLogic.cpp: line 14: ` int main(){'``` obviously the numbers 'changed' it must be a different version... How did you ever get this far?
hi,

my errors have been solved. Excuse me i think it was a fault i do not run my cpp program with sh i think it is a text mistake. i compile it with makefile and gcc
and then run the code just by ./fuzzycode2.bin . i want just trying with these sample code that you sent me to learn more and i do not like you to do it for me.
Now i just use your sample and should change it for doing something that i want.
Regarsds the thing that you said me that my cpp code has 3 values that all are null, i just put them as a symbol in my code. for the first step of the code i put instead of them some values. for example:

fuzzy-->Setinput(1,8);
fuzzy-->Setinput(2,9);
fuzzy-->Setinput(3,0);

after that i want to pass these values from shell script i put these 3 (Acc, Get ,Asset) as symbols in it for sending these values later to it.
anyway
thanks for your kind and help

Last edited by samasara; 08-20-2013 at 10:12 AM.

 08-19-2013, 03:22 PM #18 climaxnix LQ Newbie   Registered: Nov 2004 Distribution: Debian GNU/Linux Posts: 12 Rep: congragulations...
 08-20-2013, 03:04 AM #19 samasara Member   Registered: Aug 2013 Posts: 34 Original Poster Rep: Pass the output of a shell script to c++ program Reply to Thread Hi dear users, I edit my code and i get what i wanted. Really thanks for your kind and help.
08-20-2013, 03:12 AM   #20
Firerat
Senior Member

Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep:
Quote:
 Originally Posted by samasara Hi dear users, I edit my code and i get what i wanted. Really thanks for your kind and help.
what climaxnix said

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post kalyanilinux Programming 13 02-01-2012 11:06 AM VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 10:12 PM digity Linux - Newbie 5 01-07-2010 06:48 AM BrianK Linux - General 4 11-11-2008 07:27 PM

All times are GMT -5. The time now is 08:20 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -