i am capturing system call output using pipe. Command i am running is the following :-
ps -ef | grep "/home/code/service" | grep 14011 | awk '{print $NF}'
when i execute above command on command prompt it give me one integer value say 197.
when i execute same command using pipe , i am getting the following :-
$NF}'
$NF}'
197
Above output order is in random order , so it could be the follwing :-
$NF}'
197
$NF}'
I am using similar code( by waqas ) mentioned in below link :-
How to execute a command and get output of command within C++ using POSIX?
I am passing command to pipe using following way :-
std::stringstream sstr ;
sstr<<"ps -ef | ";
sstr<<"grep \"/home/code/service/\" | grep ";
sstr<<ppid;
sstr<<" | awk \'{print $NF}\'";
FILE* pipe = popen((sstr.str()).c_str(), "r");