Here the code for the above problem. Took out all unnecessary balast. it wouldn't even create the file in the first place.
desti_dir: destination directory
source_dir: source directory.
Thanks for anybody's help. It's frustating if it does work after half a day.
Code:
int do_process(QUALIFIERS * in, char * mode) ---->>> called from main
{
int status, i;
char t_command[250];
int commandlen;
int out;
char out_file[50];
sprintf(out_file,"%s/%s",in->dest_dir,"file03567.redir");
out = open(out_file[0], O_WRONLY|O_CREAT);
sprintf(t_command,"Converter k %s/%s ", in->source_dir,"file03567");
dup2(out, 1); // redirect output to the file
status=RW_startProgram(getenv("EXE"),&t_command[0]);
wait(&status);
return SUCCESS;
int RW_startProgram( char* path, char* commandline )
{
/**************************************************************/
/* */
/* start program, where */
/* path: path of the executable program in commandline */
/* commandline: command line string containing */
/* executable program with zero, one or */
/* more arguments */
/* */
/* returns: */
/* =-2 invalid command line,can not be splitted */
/* =-1 can not start child process */
/* or fork error */
/* =mypid successfully */
/**************************************************************/
char *argv[100];
int argc=0;
char start_path[PATH_MAX];
int my_pid;
/* first get command line and split into argv */
/* and get number of command line arguments */
/* path like /appl/chprd/exe/" */
argc = CHsplitCommandLine(commandline, argv, 100); --->> splits commandline in arguments
if(argc <= 0 )
{
trace("pe","invalid command line"); --> trace is a routine to print msg with timestamp return (-2);
}
/* prepare arguments for call execv(path,argv), */
/* where argv must be terminated with NULL pointer */
sprintf(start_path,"%s%s", path, argv[0]);
/* let's have some children */
/* sleep random time to avoid conflicts */
CHrandomSleep();
fflush(stderr);
switch ( my_pid = (int)fork() )
{
case -1: /* fork failure, start alarm */
return(-1);
case 0: /* this is the child process */
errno=0;
execv(start_path, argv);
/* if process successful started, program end hier */
trace("pe","CHILD pid %d: Unsuccesfull exec. Errno :%d -- %s",(int)getpid(), errno,strerror(errno));
fflush (stderr);
exit(-1);
default: /* this is the parent process */
break;
}
/* if disconnected before fork do this: */
wait(&my_pid);
trace("pi"," End of start command (pid: %d, parent %d)",getpid(),getppid());
return(my_pid);
}