コマンドライン引数であるGithubレポにgit checkout -- .
を呼び出す簡単なプログラムを作成しようとしています。私はそれを> clearRepo repoName
のように呼びたいと思います。私はすべてのリポジトリを同じGithubディレクトリに保存します。次のようにコンパイル済みCプログラムをLinuxで実行しているときに許可が拒否されました
コードは次のとおりです。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
void print_error()
{
fprintf(stderr, "Error executing: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
void print_usage(char* this)
{
printf("SYNTAX ERROR:\n%s [directoryName]\n", this);
exit(EXIT_FAILURE);
}
int main(int argc, char **argv)
{
if(argc != 2)
{
print_usage(argv[0]);
}
pid_t pid = fork();
if (pid == 0)
{
static char* params[] = {"git", "checkout", "--", ".", NULL};
char s[50], s2[50];
strcpy(s, "/home/myname/Documents/Github/");
strcpy(s2, argv[1]);
strcat(s, s2);
printf("s: %s\n", s);
int err = execv(s, params);
if(err == -1)
{
print_error();
}
exit(127);
}
else
{
waitpid(pid, 0, 0);
}
return 0;
}
それは罰金コンパイルが、print_error()Error executing: Permission denied
私はそれを実行するたびに吐き出すます。私はLinux用のプログラムを書くことにあまり慣れていないので、おそらく簡単な間違いです。私が間違っていることに関する情報は高く評価されています。ありがとう。
私は、execの最初のパラメータは何らかの理由で実行するためのディレクトリた印象の下にありました。あなたが言ったようにchdirを呼び出すだけで、execv paramをgitのパスに設定する必要があります。ありがとう! –