
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>



void error(char *msg)
{
     fprintf(stderr,"%s : %s\n",msg,strerror(errno));
     exit(1);
 }
void open_url(char *url)
{
     char launch[255];
     sprintf(launch,"cmd /c start %s",url);
     //printf("launch : %s",launch);
     system(launch);
     
}
int main(int argc, char *argv[])
{
    char *phrase = argv[1];
    char *vars[]={"RSS_FEED=http://r...content-available-to-author-only...n.com/services/podcasting/sitroom/rss.xml",NULL};
    int fd[2];
    if(pipe(fd)== -1) {
                  error("Can't create the pipe");
    }
    pid_t pid = fork();
    if(pid== -1) {
             error("Can't fork process");
    }

    if(!pid){
        dup2(fd[1],1);
        close(fd[0]);
        if(execle("C:/Python27/python","C:/Python27/python","./RSS_Gossip/rssgossip.py",
                  "-u",phrase,NULL,vars) == -1){
                error("Can't run script");
            }
        }
        
     dup2(fd[0],0);
     close(fd[1]);
     char line[255]; 
     while(fgets(line,255,stdin)){
     // 如果line以tab開頭是url, line+1是tab以后的字符串
                                  if(line[0]=='\t')
                                  open_url(line+1);
     }   
    
    return 0;
}

