Head First C ―頭とからだで覚えるCの基本
(オライリージャパン)
David Griffiths (著) Dawn Griffiths (著)
中田 秀基(監訳)(翻訳) 木下 哲也 (翻訳)
開発環境
- OS X Yosemite - Apple, Ubuntu (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang/LLVM (コンパイラ, Xcode - Apple)
Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の10章(プロセス間通信: お話は楽しい)、エクササイズ(p.447)を解いてみる。
その他参考書籍
- 21st Century C: C Tips from the New School
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
- C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、 谷口 功 (翻訳)、 オライリージャパン)
エクササイズ(p.447)
コード(BBEdit, Emacs)
news_opener.c
#include <stdio.h> #include <unistd.h> #include <error.h> #include <open_url.h> int main(int argc, char *argv[]) { char *phrase = argv[1]; char *vars[] = {"RSS_FEED=http://rss.cnn.com/rss/edition.rss", NULL}; int fd[2]; if (pipe(fd) == -1) error("パイプを作成できません"); pid_t pid = fork(); if (pid == -1) error("プロセスをフォークできません"); if (!pid) { close(fd[0]); dup2(fd[1], 1); if (execle("/usr/bin/python", "/usr/bin/python", "rssgossip.py", "-u", phrase, NULL, vars) == -1) error("スクリプトを実行できません"); } dup2(fd[0], 0); close(fd[1]); char line[255]; while (fgets(line, 255, stdin)) if (line[0] == '\t') open_url(line + 1); return 0; }
Makefile
P=news_opener CC=cc CFLAGS=-g -Wall # -O3 SRC=news_opener.c OBJ=~/root/object_files/*.o news_opener.o LDLIBS= $(P): $(OBJ) $(CC) $(CFLAGS) $(LDLIBS) $(OBJ) -o $@
入出力結果(Terminal)
$ make cc -g -Wall -c -o news_opener.o news_opener.c cc -g -Wall ~/root/object_files/*.o news_opener.o -o news_opener $ ./news_opener US sh: cmd: command not found sh: line 1: x-www-browser: command not found sh: line 1: Makefile: command not found sh: cmd: command not found sh: line 1: x-www-browser: command not found sh: line 1: Makefile: command not found sh: cmd: command not found sh: line 1: x-www-browser: command not found sh: line 1: Makefile: command not found sh: cmd: command not found sh: line 1: x-www-browser: command not found sh: line 1: Makefile: command not found LSOpenURLsWithRole() failed with error -1712 for the URL http://edition.cnn.com/2014/11/13/politics/holder-presser/index.html?eref=edition%0A. sh: cmd: command not found sh: line 1: x-www-browser: command not found sh: line 1: Makefile: command not found LSOpenURLsWithRole() failed with error -1712 for the URL http://edition.cnn.com/2014/11/13/living/irpt-lady-movember-lokey/index.html?eref=edition%0A. sh: cmd: command not found sh: line 1: x-www-browser: command not found sh: line 1: Makefile: command not found LSOpenURLsWithRole() failed with error -1712 for the URL http://edition.cnn.com/2014/11/12/opinion/parini-new-text-jesus-married-with-kids/index.html?eref=edition%0A. sh: cmd: command not found sh: line 1: x-www-browser: command not found sh: line 1: Makefile: command not found LSOpenURLsWithRole() failed with error -1712 for the URL http://edition.cnn.com/2014/11/13/world/europe/russia-bombers-plan/index.html?eref=edition%0A. $
0 コメント:
コメントを投稿