fork()
Linuxで外部コマンドを実行するためにとの組み合わせを使用してきましたが、実際のバイナリへのシンボリックリンクでexec()
あるコードを実行しようとすると、コードが失敗するようです。/usr/bin/firefox
この問題を解決する方法を知っている人はいますか?私は他のプログラム(実際には実行可能なバイナリであり、それらへのシンボリックリンクではありません)でテストしましたが、動作します。
プログラムのコードは次のとおりです。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
int main(int argc, char **argv) {
pid_t pid;
// this was the old line:
// char *parmList[] = {"", "index.html", NULL};
// and this is the one that solves the problem:
char *parmList[] = {"firefox", "index.html", NULL};
int a;
if ((pid = fork()) == -1)
perror("fork failed");
if (pid == 0) {
a = execvp("/usr/bin/firefox", parmList);
fprintf(stdout, "execvp() returned %d\n", a);
fprintf(stdout, "errno: %s (%d).\n", strerror(errno), errno);
}
else {
waitpid(pid, 0, 0);
}
return 0;
}
編集:コードを更新して回答を含め、トピックのタイトルを変更しました。問題は実際にはシンボリック リンクが原因ではないように思われたからです。みんな、ありがとう。