C - プロセスとシステムサービス - 限界を超える - Pythonスクリプトの実行
Head First C ―頭とからだで覚えるCの基本、 David Griffiths(著)、 Dawn Griffiths(著)、 中田 秀基(監修)、 木下 哲也(翻訳)、 O’Reilly Media)の 9章(プロセスとシステムサービス - 限界を超える)、p.417(エクササイズ)の解答を求めてみる。
Makefile
all: newsbound rssgossip.py
./newsbound database
newsbound: newsbound.c
cc newsbound.c -o newsbound
コード
newsbound.c
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *feeds[] = {"https://cs.mkamimura.com/posts/index.xml",
"https://math.mkamimura.com/posts/index.xml",
"https://book.mkamimura.com/posts/index.xml"};
int times = 3;
char *phrase = argv[1];
for (size_t i = 0; i < times; i++)
{
char var[255];
sprintf(var, "RSS_FEED=%s", feeds[i]);
char *vars[] = {var, NULL};
if (execle("/opt/local/bin/python", "/opt/local/bin/python", "rssgossip.py",
phrase, NULL, vars) == -1)
{
fprintf(stderr, "スクリプトを実行できません:%s\n", strerror(errno));
return 1;
}
}
}
入出力結果(Terminal, Zsh)
% make
./newsbound database
Databases テーブル、自己結合、重複の回避
Databases 2つのテーブル、結合、INNER JOIN、合計、平均、最大、最小
Databases 2つのテーブル、結合、INNER JOIN
Databases テーブルの作成、データの挿入、データの表示、例外処理、OperationalError
Databases データの取得、select、条件、where、and、or、演算子、大小
Databases テーブルの作成、データ型、CREATE、INSERT、SELECT、SQLite、connect、cursor、execute、fetchall
%