別の C アプリケーション内から 2 つの C アプリケーションを呼び出すにはどうすればよいですか?
例:
pg1.c can be run as ./a.out pg1_args
pg2.c can be run as ./a.out pg2_args
次のように実行できるプログラムを書きたいと思います。
./a.out pg1_args pg2_args
結果は次のようになります。
./a.out pg1_args
./a.out pg2_args
./a.out pg1_args
./a.out pg2_args
ここの pg1 は svm_scale で、ここの pg2 は svm_predict で、どちらも libsvm から取得しました: http://www.csie.ntu.edu.tw/~cjlin/libsvm/
[ 編集 ]
@ジョナサン、
私はこの概念を試すためにこれらのプログラムを書きました..
pg1.c
#include <stdio.h>
#include <string.h>
int main(int argc,char **argv)
{
FILE *fin;
fin=fopen("pg1file.txt","a");
fprintf(fin,"%s",argv[1]);
fflush(fin);
fclose(fin);
}
pg2.c
#include <stdio.h>
#include <string.h>
int main(int argc,char **argv)
{
FILE *fin;
fin=fopen("pg2file.txt","a");
fprintf(fin,"%s",argv[1]);
fflush(fin);
fclose(fin);
}
pg3.c:
#include<stdio.h>
#include<string.h>
int main(int argc,char **argv)
{
int i;
const char *cmd1 = strcat("./pg1 ",argv[1]);
const char *cmd2 = strcat("./pg2 ",argv[2]);
for(i=0;i<4;i++)
{
if (system(cmd1) != 0)
printf("\n error executing pg 1");
if (system(cmd2) != 0)
printf("\n error executing pg 2");
}
}
[root@localhost trinity]# ./a.out first second
Segmentation fault (core dumped)
[root@localhost trinity]#
誰かが私が間違ったことを説明できますか?