473,383 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

simple program on execv() function

Sir please consider the following....
I would like to copy contents from one file (mart1.c) to another file (mart2.c) using execv() function (using command line arguments).....
The command line argument string is "cp mart1.c mart2.c"
Consider the following code..
int main (int argc, char *argv[])
{
char c[]="cp mart1.c mart2.c";
argv[0]=strtok(c," " );
argv[1]=strtok(0," " );
argv[2]=strtok(0," ");
execv("/bin/cp","cp",argv);
}
The contents are not getting copied when I run this code...Is there mistake in the code..Kindly correct the above code...
Thank you..
May 6 '07 #1
3 13369
Motoma
3,237 Expert 2GB
I have moved this thread to the C forum. Hopefully you will find help there.
May 9 '07 #2
gpraghuram
1,275 Expert 1GB
Hi,
Expand|Select|Wrap|Line Numbers
  1. int main (int argc, char *argv[])
  2. {
  3. char c[]="cp mart1.c mart2.c";
  4. //argv[0]=strtok(c," " ); //Instead of assigning do strcpy
  5. strcpy(argv[0],strtok(c," " ));
  6. argv[1]=strtok(0," " );
  7. argv[2]=strtok(0," ");
  8. execv("/bin/cp","cp",argv);
  9. }
  10.  
  11.  
Replace assignment with strcpy and then try it...that will solve the issue.

Thanks
Raghuram
May 9 '07 #3
Hi,
Expand|Select|Wrap|Line Numbers
  1. int main (int argc, char *argv[])
  2. {
  3. char c[]="cp mart1.c mart2.c";
  4. //argv[0]=strtok(c," " ); //Instead of assigning do strcpy
  5. strcpy(argv[0],strtok(c," " ));
  6. argv[1]=strtok(0," " );
  7. argv[2]=strtok(0," ");
  8. execv("/bin/cp","cp",argv);
  9. }
  10.  
  11.  
Replace assignment with strcpy and then try it...that will solve the issue.

Thanks
Raghuram
Thank you Sir....
Sir could u please tell me the difference between copying and assigning...
Thank you...
May 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mike Vieths | last post by:
I'm running into a problem when I try to run commands with os.execv. It seems to be putting quotation marks around each element of the list passed as its second argument. This is fine for the...
5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
2
by: New | last post by:
How can I uses a pipe to get the output from a execv() and redirect it to a parent process? in ansi c if possible Thank-you
3
by: Douglas Dillon | last post by:
I am trying to use tiffcp to reconfigure tif files (if they are tiled) to nontiled so I can use existing code to handle them. However, I am having issues providing the arguments. The app is run...
1
by: freehomesp | last post by:
1 #include <sys/types.h> 2 #include <sys/times.h> 3 int 4 main(int argc,char* argv) 5 { 6 struct tms before, after; 7 8 times(&before); 9 10 pid_t pid;
5
by: ash | last post by:
hi, i want to know is there a way to run/control an external program form within a python program? thanks in advance for any support.
1
by: Þ­¾¯ | last post by:
/************************************************** *** *** chrexec.c *** *This shit can be called from root or from any user (in that case executable * should have 06755 permisions) and should...
5
by: michael | last post by:
Hi All, I am trying to create an array the same as the char *argv that is passed to main() ie main(int argc, char *argv) I need to store a pointer to and integer in one of the elemets, but the...
3
by: CMorgan | last post by:
Hi everybody, I am experiencing an annoying problem with fork() and execv(). In my program I need to launch the "pppd" from a thread, so, I create a new process with fork and then in the child...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.