[comp.lang.c] Spawning a DOS child process

njarhe@ee.ualberta.ca (The Bill Man) (06/14/91)

I am having a problem spawning a DOS child process.  What I am trying to do is 
to spawn the xcopy command to copy a given file to a disk drive.  What ends
up happening is the command either recognizes the given file and copies it to
the current directory or it recognizes the disk drive and copies what is on
the disk to the current directory. 

If anyone knows how the spawn (exec...) command works I would appreciate some
hints on how shy mine is going wrong.

BTW I am using Borland C++ on a MegaCom XT turbo (if that is necessary to know).

The following is a sample of what I am trying to do.

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <errno.h>

int main(void)
{
 cha  path_to_file[40],
      disk_drive[5],
      filename[15];

 int result;

 clrscr();
 printf("\n\n     Enter the name of the file to copy to disk : ");
 scanf("%s",filename);

 while (strlen(filename) > 12)
 {
  clrscr();
  printf("\n\n     Re-enter the name of the file to copy to disk : ");
  scanf("%s",filename);
 }

 sprintf(disk_drive," a: ");
 sprintf(path_to_file,"c:\\drill\\data\\%s",filename);

 result = execlp("xcopy.exe",path_to_file,disk_drive,NULL);

 if (result == -1)
 {
  perror("Error from execlp");
  exit(1);
 }

 return 0;
}

Please respond by E-mail.

Thanks in advance.

Bill Njarheim

E-Mail : njarhe@ee.ualberta.ca

        //                                                            //
 $$$$$$$$  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    $$$$$$$$$
$$$   //   $                                              $   $$$   //
 $$$ //    $	THE BILL MAN				  $    $$$ //
   $$$     $						  $      $$$ 
   //$$$   $ YOU CAN PAY ME NOW, OR YOU CAN PAY ME LATER! $	 //$$$
  //  $$$  $ 						  $	//  $$$	
$$$$$$$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$  $$$$$$$$$
//						              //