Re: [Fwd: Re: How to use a shell command in an application?]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 10, 2005 at 11:12:40 +0530, Sandeep wrote:
> /****************************************************/
> // Below is the example of executing shell command
> // "cat > /proc/iomem" from application
> //
> /****************************************************/

1) Are you sure you want to invoke "cat > /proc/iomem" and not simply
   open /proc/iomem for writing ?!?!
2) Are you sure you want to *write* to /proc/iomem? I'd bet you really
   want to read from it -- now that's "cat /proc/iomem" from shell (and
   just opening it for read in C code).

> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <stdio.h>
> 
> int main(void)
> {
>         int fd_exec;
>         char *const arg_list[]= {
>                 "cat",
>                 "/proc/iomem",
>                 NULL
>         };
>         if(fork() == 0)
>         {
> 	/*** Please note below 3 statements can be replaced by the above two
>            statements viz close(1) & open(...) ***/
>                 fd_exec = open("/tmp/iomemdump", O_CREAT | O_WRONLY );
>                 dup2(fd_exec,1);
>                 close(fd_exec);
>                 execvp("/bin/cat",arg_list);
>         }
>         printf("Hello\n");
>         return 0;
> }

Hm. You are really invoking "cat /proc/iomem > /tmp/iomemdump". Could
you pleas explain the point in doing so? You want to simply read
/proc/iomem, no?

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux