#include <stdio.h>#include <iostream> #define MAX_BUFFER 1000 using namespace std; string getOutput(string); int main(int argc, char *argv[]){ string val = getOutput("ps -lae | grep señal |tr -s \" \" \":\" | cut -d: -f 4"); cout << val; return 0;} string getOutput(string cmd){ string data; FILE *stream; char buffer[MAX_BUFFER]; // i set it to 1000 chars, don't forget to increase for bigger input stream stream = popen(cmd.c_str(), "r"); // opens the stream while(fgets(buffer, MAX_BUFFER, stream) != NULL) // stores the input stream into buffer data.append(buffer); // while data is stored in the buffer, append to the data string pclose(stream); // closes the stream return data;}
And no matter, if you didn't give a value to the declaration, the compiler always sets the string and char to null, and integer to 0.
bagun wrote:Stake your code has a error in line 31 i remember.Today i will revise it and tell you something.
Then that is not my code. There is no line 31 in mine, only 28 at the most. Insert a new line at the end, because some compilers don't like "new lineless" codes.
bagun wrote:Stake your code has a error in line 31 i remember.Today i will revise it and tell you something.
Then that is not my code. There is no line 31 in mine, only 28 at the most. Insert a new line at the end, because some compilers don't like "new lineless" codes.
I made some modifications on your code.Now i cant access it,i will tell you later