Prev: Create staple diagrams from a text file (containing numbers)from command line?
Next: using --prefix= in my code
From: Rich on 3 Feb 2010 20:25 Hi, I have a program that needs to gzip some files. When I run the program I get permission denied. I have tried with execl and execlp and I get permission each time the program try to run gzip. What did I do wrong? Thanks, #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main() { int i, ret; char filename[30]; for (i=1;i<5;i++) { memset(filename,0,sizeof(filename)); snprintf(filename,30,"gzip -9 -f test%d.txt", i); ret=execlp(".", "gzip", filename, NULL); // ret=execl("./", "gzip", "-f", "test", NULL); if (ret < 0) { printf("Can't compress file: ret = %d error = %d\n",ret,errno); printf("The problem is = %s\n", strerror(errno)); exit(EXIT_FAILURE); } } return 0; }
From: Ben Bacarisse on 3 Feb 2010 22:11 Rich <rtillmore(a)gmail.com> writes: > On Feb 3, 7:48 pm, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: <snip> >> -- >> Ben. It's best to snip sigs. In fact, snip everything except what is needed for context or comment. > Thank you at least now the program gzip's without error. However it > only gzips the first file and the programs exits. No error messages > no nothing is displayed. > > If I comment out the execlp line the program does loop 5 times. With > the execlp compiled in the loop executes once. Now what? I missed the loop the first time round. The exec functions replace your process with a new one. Once you exec your program is gone. You probably want system(3) or popen(3). BTW, what source are you using for learning this stuff? Asking in Usenet at each stage is likely to be slower than a good text about Unix programming. <snip> -- Ben.
From: Rich on 4 Feb 2010 21:46 On Feb 3, 9:11 pm, Ben Bacarisse wrote: > Rich writes: > > On Feb 3, 7:48 pm, Ben Bacarisse wrote: > <snip> > > I missed the loop the first time round. The exec functions replace > your process with a new one. Once you exec your program is gone. You > probably want system(3) or popen(3). > > BTW, what source are you using for learning this stuff? Asking in > Usenet at each stage is likely to be slower than a good text about > Unix programming. I will look into popen and system. I am using my 15 year old C book. It doesn't mention exec, popen, or system. I found the thread that listed some free C books and The C Book doesn't mention exec either. It is probably time to buy a new book :) Thanks,
From: Ersek, Laszlo on 4 Feb 2010 22:30 In article <a5fbfcd2-b6c5-411e-96bd-8d22b1e9ccf7(a)r19g2000yqb.googlegroups.com>, Rich <rtillmore(a)gmail.com> writes: > I will look into popen and system. I am using my 15 year old C book. > It doesn't mention exec, popen, or system. I found the thread that > listed some free C books and The C Book doesn't mention exec either. > It is probably time to buy a new book :) http://www.opengroup.org/onlinepubs/9699919799/functions/exec.html
From: Ersek, Laszlo on 4 Feb 2010 22:37
In article <438a3533-9bf4-482f-aae3-c6d07024507b(a)q16g2000yqq.googlegroups.com>, Rich <rtillmore(a)gmail.com> writes: > I am using Linux. Try posix_spawn(). http://www.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html $ less /usr/include/spawn.h You could also try to do the compression yourself with zlib. http://zlib.net/manual.html#Gzip Cheers, lacos |