0
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>

typedef struct msgbuf {
	long mtype;
	FILE *mtext;
} message_buf;

main(){
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
if ((msqid = msgget(key, msgflg )) < 0){
	perror("msgget");
	exit(1);
}

sbuf.mtype = 1;
sbuf.mtext = popen("df", "r");
buf_length = strlen(sbuf.mtext) + 1;

if(msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) {
	printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
	perror("msgsnd");
	exit(1);
}
else
	printf(sbuf.mtext);
	exit(0);
	}

Hi there, this is my code, i have a problem like that in the topic. I dunno where is the problem, anyone see anything ?

3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by oieronle
0

so what do i have to change in my code to make it compilable, to let it use popen structure ?

0

you don't. Use fgets() to read the data from the port until there is no more data to read -- fgets() returns NULL. Its very much like reading data from a file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.