How use exec, execlp, ....


 
Thread Tools Search this Thread
Top Forums Programming How use exec, execlp, ....
# 1  
Old 10-25-2011
How use exec, execlp, ....

Hello,

I need to do a function in ansi c for linux that work like command cp.I try with this but doesn't work:

Code:
int copy (char *src, char *dst)
{
ret = execlp("/bin/cp", "cp", "/home/linux/working", (char*)src,(char*)dst)
return 0;
}

The copy function must do the next "cp origein.txt destiny.txt" using th path directory called "/home/linux/working"

Thanks!

Last edited by radoulov; 10-25-2011 at 04:36 PM.. Reason: Code tags!
# 2  
Old 10-25-2011
Did you bother to read the manpage of the execlp function...
# 3  
Old 10-26-2011
This also sounds like homework, and my bet is that they don't want you to call the system's copy function, rather they want you to open the two files in binary and read from one and write to the other.

Read the man pages for, fopen, fread, fwrite, and fclose. You can figure out the number of bytes you need to copy with fseek and ftell.

Or, hey, just Google search the source for the cp function Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Problem with fork() and execlp process

Hello everyone, this is my first post. I have a task to use a fork to create multiple processes and then use execlp to run another program to add 2 numbers. The problem I am having is we are supposed to use the exit() call in the execlp to return the small integer. This is a bad way to... (3 Replies)
Discussion started by: Johnathan_1017
3 Replies

2. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

3. UNIX for Advanced & Expert Users

Using -exec with and without -name

Hi, I need to delete the last N days file using find. I am trying to use find . -mtime -10 -print which lists down required files. but when i use find . -mtime -10 -exec ls -lrt {} \; it gives me all files in the directory including the required files but the required files... (7 Replies)
Discussion started by: v_m1986
7 Replies

4. UNIX for Advanced & Expert Users

-exec cp

Hi, on AIX 6.L I want to copy the result of grep -v to test directory then : `hostname`@oracle$ls -l | grep -v RINT -exec cp {} test grep: can't open -exec grep: can't open cp grep: can't open {} test:°`. Can you help me ? Thank you. (3 Replies)
Discussion started by: big123456
3 Replies

5. UNIX for Dummies Questions & Answers

How it work?? the execlp

int main () { int p=1; while (p>0) p=fork(); execlp("prog",prog",Null); return 0; } and thanks :b: (1 Reply)
Discussion started by: foufo07
1 Replies

6. HP-UX

ENOENT error occurs while issueing execlp command

/************************************************************************ * * TEST NAME: setrlimitd_su.c * * PURPOSE: To verify the soft (rlim_cur) and hard (rlim_max) limit * of process RLIMIT_DATA resources correctly inherited by * the exec() system call. * * RESULT: function call should... (1 Reply)
Discussion started by: mansa
1 Replies

7. UNIX for Advanced & Expert Users

exec

I have read that exec "replaces the current process with a new one". So I did $ exec ls and after this executed, my shell disappeared. I am assuming that my shell had PID xyz, and when I did exec ls, this ls got pid xyz, and when it terminated, there was no more shell process running, and... (5 Replies)
Discussion started by: JamesByars
5 Replies

8. Programming

execlp to sort

Hi, I have a very small program where I call execlp() to execute sort. Everything works fine. But sort has a -T option which can be used to specify a temporary directory. Now when I use -T with execlp() it does not work. #include <stdio.h> #include <stdlib.h> #include <string.h> #include... (4 Replies)
Discussion started by: the_learner
4 Replies

9. Shell Programming and Scripting

exec

In exec function say when i would like to remove the files exec rm{}\; Why is this "\" needed immediately after {} and what if i dont give it? TIA, Nisha (1 Reply)
Discussion started by: Nisha
1 Replies

10. Programming

execvp and execlp?

Hi mates, Is there any difference between execvp and execlp? any comment will be appreciated. abdul:) (1 Reply)
Discussion started by: abdul
1 Replies
Login or Register to Ask a Question