1

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");
Community
  • 1
  • 1
user1057741
  • 265
  • 1
  • 2
  • 10
  • Please show us how **exactly** you are calling this from C. – alk Oct 07 '13 at 10:19
  • Note that `std::stringstream` is just a massive syntax error in C. You seem to be using C++, not C. If you don't know which language you're programming in, it is not surprising you can't write good code in it. – Jonathan Leffler Oct 08 '13 at 05:27
  • Ok, thanks. Now please also show us how you pull and print the result of the command issued via `popen()`. – alk Oct 08 '13 at 16:53
  • in same way mentioned in http://stackoverflow.com/questions/478898/how-to-execute-a-command-and-get-output-of-command-within-c link – user1057741 Nov 11 '13 at 05:29

0 Answers0