using system cp command in C program


 
Thread Tools Search this Thread
Top Forums Programming using system cp command in C program
# 1  
Old 09-16-2005
using system cp command in C program

Hi

i used the following code to copy a directory from a source location to dest.

argv[1] contains the source loc i/p by the user.

strcpy(source,argv[1]);
strcpy(dest,"/home/MainServer/Job_dir/");
system("cp -r $source $dest");

it complies properly but during execution of the program it gives the following warning:
try cp --help

can anyone help me out with this?

thanx!
# 2  
Old 09-16-2005
try with these modifications

char str[100];

strcpy(source,argv[1]);
strcpy(dest,"/home/MainServer/Job_dir/");
/* system("cp -r $source $dest"); */

sprintf(str,"cp -r %s %s", source, dest);
system(str);
# 3  
Old 09-20-2005
U can not use $ with C variables as in shell. U have to use sprintf() to format the command in a string and then pass that string to system().
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help with Execl system call in a C program?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: "Your a7.c program should use printf to print a nice message. (You can decide what to say.) Then the process... (9 Replies)
Discussion started by: miniviking10
9 Replies

2. UNIX for Advanced & Expert Users

UNIX System Programming Certification Program

Hi, I was working in an IT firm. My stream was UNIX, C, C++. worked for an year and half and then left the job. there has been a gap of 2 years already and wanna get back again. i have some 6 more months to that. want to do some certification to help me get back. c,c++ are fine. unix system... (1 Reply)
Discussion started by: niaR
1 Replies

3. UNIX for Dummies Questions & Answers

I am not able to use variables in system command in a C program

this method is not working.I am having a problem to use variables in system command. i cannot use the variables in system command. this how i was did system("whereis command"); this method works very fine. but, i want use the commands as variable. that means i want only pass the variables.... (6 Replies)
Discussion started by: dhanda2601
6 Replies

4. Programming

Notification email in C program, via system call? or?

Hello everyone! I'm quite new here, but this forum helped me a lot before without registering :-) I'll go directly to my problem, I have been searching a bit about this issue but I was not successful. I need to write a program in C code to notificate me (to my email) when some action is done... (7 Replies)
Discussion started by: RoNNo
7 Replies

5. Programming

A question about the system call mount in a C program

Dear all, Currently I'm working on a C program (OS = ubuntu 9.0.4)in which a USB key will be mounted and umounted for several times. I read the man page of the mount system call. I use the following test code #include <sys/mount.h> int main(int argc, char *argv) { if... (5 Replies)
Discussion started by: dariyoosh
5 Replies

6. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

7. Windows & DOS: Issues & Discussions

XP as a program on Unix/Linux system?

I am sure this question has been asked and answered before, also, if it is the wrong catergory, please let me know. I would like to know how, if possible to run Unix/Linux as my operating system, and then load XP as a program? (I am open to other operating systems, but it has to be able to... (3 Replies)
Discussion started by: mountainwolf
3 Replies

8. AIX

system() in a c++ program halts in AIX 5.3

system() in a c++ program halts in AIX 5.3, though the corresponding binary working fine in AIX 5.2 and lower version. I am executing a script using system in a c++ program. the script has the execute permission by all. (0 Replies)
Discussion started by: Amiya Rath
0 Replies

9. Programming

Program for a UNIX system

I'm looking for a programmer to write a Program for The Unix Environment. The program is quite simple, but have to be well written. For information please contact me via private message or via msn messenger (0 Replies)
Discussion started by: dracox86
0 Replies
Login or Register to Ask a Question