[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Shell commands in linux





On Fri, 31 Mar 2000, Binand Raj S. wrote:

> Hmm... For system, something like:
> 
> char cmdbuf[100];
> sprintf (cmdbuf, "ls -al");
> system (cmdbuf);
> 
> is what you should do. Use that sprintf to your advantage.
> 
> You should be using one of the other exec* functions instead of execve. I
> prefer execv, but you might like execl or one of the others better.
> To execute a program, I do something like:
> 
> char *cmd[3];
> /* malloc here for cmd[0-2] */
> strcpy (cmd[0], "/bin/ls");
> strcpy (cmd[1], "/bin/ls");
> strcpy (cmd[2], "-al");
> cmd[3] = NULL;
> switch (pid = fork()) {
>    case -1: exit (-1);
>    case 0: execv (cmd[0], cmd);
> 	   exit (-1);
>    default: waitpid (pid, &status, 0);
> 	    /* Process status here */
> }
> 
> Binand
> 
> -- 
> The prompt for all occasions:
> export PS1="F:\$(pwd | tr '/[a-z]' '\134\134[A-Z]')> "
> --------------- Binand Raj S. (binand@xxxxxxxxxxxxxxxxxxxxx)
> 
> 
> -----------------------------------------------------------------------
> For more information on the LIP mailing list see:
> http://lists.linux-india.org/lists/LIP
> 
	
	Sorry that went right over my head. What does it mean. Can you
make it a bit more cheedu-friendly ?

bye
cheedu