c - Redirecting execvp path -


i'm trying write simple code execute program subfolders input file , print thr result output file.

my problem when execute program keeps failing on me. since execvp command trying exe named "a.out" on wrong location. in (desktop rather searching correct path address).

here's code. please me out :)

pid_t   runner; char enter[] = "/home/demo/desktop/os/ex1/ex12/code/input.txt"; // input file char path[] = "/home/demo/desktop/os/ex1/ex12/ex1/ronen/"; correct path char *r [] = {"./a.out", null};  int savedfd = dup(0); int sever2fd=dup(1); int fdin = open(enter,o_rdonly); int fdout = open ("output.txt", o_creat | o_rdwr, 0466); dup2(fdin,  0); dup2(fdout, 1); if ((runner = fork()) < 0) {perror("could not make fork");} else if (runner == 0) {     if (execvp(r[0],r) < 0 ) {printf("failed!\n");} } else if (runner != 0) {     waitpid(runner,0,0);     dup2(savedfd, 0);     dup2(sever2fd, 1);     printf("done\n"); } close(fdin);close(fdout); 

the answer simple.

"chdir(wanted path)" int dirchange = chdir(argv[1]);


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -