redirect console output to a String?
Hi all,
I am new to C and am writing a small application in C. One part of it is to fire some system commands and store the output in some variable.
A small example of what i wanna do:
Code:
int main(void)
{
return system("ifconfig | grep 'inet addr'");
}
now i want to store the output of system() in a string (or an array of String). I tried out many things but nothing seems to work.
Will be very happy if somebody could help me out in this :)
*** stack smashing detected ***
Hi all,
Does anybody has some idea why this piece of code
Code:
int setIP(char fName[100])
{
FILE *pipein_fp;
char readbuf[100];
char cmd[] = "vmware-cmd ";
char var[] = " setguestinfo ip 68.180.53.46";
strcat(cmd, fName);
strcat(cmd, var);
if (( pipein_fp = popen(cmd, "r")) == NULL)
{
perror("popen");
exit(1);
}
while(fgets(readbuf, 100, pipein_fp))
printf("%s", readbuf);
pclose(pipein_fp);
printf("Server IP for VM set successfully");
return(0);
}
is generating the following error
Code:
setguestinfo(ip 68.180.53.46) = 1
*** stack smashing detected ***: ./TCPEchoServer terminated
Server IP for VM set successfullyAborted (core dumped)
Thanks