Unix Programming - exec

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2005 > exec





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author exec
friend_05

2005-10-27, 2:48 am

I making a program in C.

I want to read a file using "od -c" command, I was trying to use exec
for the same.

But I don't have much idea about exec. Can anyone suggest how to use
for od command and also of six exec function which one I should use.

-------------------------------------------------------
printf("%s",rfile);
if((execv("/usr/bin/od", "/hiren/filem.c"))<0)
perror("exec");
-------------------------------------------------------

I was using the aboce code, but it is giving bad address, I am getting
why this error is coming.

Barry Margolin

2005-10-27, 2:48 am

In article <1130386410.272701.281310@g14g2000cwa.googlegroups.com>,
"friend_05" <hirenshah.05@gmail.com> wrote:

> I making a program in C.
>
> I want to read a file using "od -c" command, I was trying to use exec
> for the same.
>
> But I don't have much idea about exec. Can anyone suggest how to use
> for od command and also of six exec function which one I should use.
>
> -------------------------------------------------------
> printf("%s",rfile);
> if((execv("/usr/bin/od", "/hiren/filem.c"))<0)
> perror("exec");
> -------------------------------------------------------


I thought you wanted to use "-c". You seem to have left that out.

>
> I was using the aboce code, but it is giving bad address, I am getting
> why this error is coming.


The second argument to execv() is supposed to be an array of strings, so
you would have to write something like:

char *exec_argv[] = {"/usr/bin/od", "-c", "/hiren/filem.c", NULL};
execv("/usr/bin/od", exec_argv);

However, when the program knows the arguments to the program being
exec'ed, execl() is usually the preferable function:

execl("/usr/bin/od", "/usr/bin/od", "-c", "/hiren/filem.c", (char*)NULL);

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com