###前提・実現したいこと
c言語でexecv
関数を使ってディレクトリを変更するプログラムの作成したい
###発生している問題・エラーメッセージ
予めtest
というディレクトリを実行ファイルと同じディレクトリに用意しcd test
でtest
にディレクトリを変更したいが
No such file or directory: No such file or directory
とエラーが出る
###該当のソースコード
C
1#include <stdio.h> 2#include <unistd.h> 3#include <string.h> 4#include <errno.h> 5 6int main(int argc, char *argv[]){ 7 char *const str[] = {"/bin/cd","test", NULL}; 8 execv("/bin/cd", str); 9 10 if(errno != 0) 11 perror(strerror(errno)); 12 13 return -1; 14} 15
###試したこと
ls
やmkdir
コマンドは↑のコードを変更して出来たのですが
cd
だけ出来ないです
/test
とかも試したのですが駄目でした
どなたか分かる方教えていただけないでしょうか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/12 03:54
2017/11/12 04:17