fork download
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <unistd.h>
  7. #include <sys/wait.h>
  8. #include <sys/types.h>
  9.  
  10.  
  11.  
  12. void error(char *msg)
  13. {
  14. fprintf(stderr,"%s : %s\n",msg,strerror(errno));
  15. exit(1);
  16. }
  17. void open_url(char *url)
  18. {
  19. char launch[255];
  20. sprintf(launch,"cmd /c start %s",url);
  21. //printf("launch : %s",launch);
  22. system(launch);
  23.  
  24. }
  25. int main(int argc, char *argv[])
  26. {
  27. char *phrase = argv[1];
  28. char *vars[]={"RSS_FEED=http://r...content-available-to-author-only...n.com/services/podcasting/sitroom/rss.xml",NULL};
  29. int fd[2];
  30. if(pipe(fd)== -1) {
  31. error("Can't create the pipe");
  32. }
  33. pid_t pid = fork();
  34. if(pid== -1) {
  35. error("Can't fork process");
  36. }
  37.  
  38. if(!pid){
  39. dup2(fd[1],1);
  40. close(fd[0]);
  41. if(execle("C:/Python27/python","C:/Python27/python","./RSS_Gossip/rssgossip.py",
  42. "-u",phrase,NULL,vars) == -1){
  43. error("Can't run script");
  44. }
  45. }
  46.  
  47. dup2(fd[0],0);
  48. close(fd[1]);
  49. char line[255];
  50. while(fgets(line,255,stdin)){
  51. // 如果line以tab開頭是url, line+1是tab以后的字符串
  52. if(line[0]=='\t')
  53. open_url(line+1);
  54. }
  55.  
  56. return 0;
  57. }
  58.  
  59.  
Success #stdin #stdout #stderr 0s 2156KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Can't run script : No such file or directory