Skip to content

Instantly share code, notes, and snippets.

@collinalexbell
Last active October 8, 2016 05:13
Show Gist options
  • Save collinalexbell/116457db6d7e7f6f42f1d00987d6ddcb to your computer and use it in GitHub Desktop.
Save collinalexbell/116457db6d7e7f6f42f1d00987d6ddcb to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
FILE * fifo;
char BUFF[500];
struct a_header{
char* name;
a_header(char* name): name(name){}
};
struct a_header *header = new a_header("foo");
struct list{
struct list *next;
char* string;
list(){
next = NULL;
string = "foo";
}
};
void FIFOstuff(struct list *L) { //L is a linked list of strings
mkfifo("q1", 0777);
pid_t pid = fork();
if (pid == 0) {
try{
execl("./myPy.py", (char *)NULL);
}
catch(int e){
printf("An exception occurred. Exception Nr. %d\n ", e);
}
} else {
fifo = fopen("q1", "w");
fprintf(fifo, "%s\n", header->name);
if(L != NULL){
printf("l != null");
};
while (L != NULL) {
fprintf(fifo, "%s\n", L->string);
L = L->next;
}
fclose(fifo);
mkfifo("q2", 0777);
fifo = fopen("q2", "r");
while (fscanf(fifo, "%s", BUFF) == 1) {
printf("%s\n", BUFF);
}
fclose(fifo);
remove("q2");
}
}
int main(){
struct list *l = new struct list();
FIFOstuff(l);
}
#!/usr/bin/python
import logging
import os
logging.basicConfig(level=logging.DEBUG, filename='myapp.log')
def reader():
text = []
with open("q1", "r") as fifo:
text.append(fifo.readline())
text.append(fifo.read())
return text
def writer(text):
with open("q2", "w") as fifo:
for line in text:
fifo.write(line)
try:
writer(reader())
except OSError:
logging.exception("Mistake")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment