[comp.unix.questions] Way over my head!

mdiehl@hydra.unm.edu (J. Michael Diehl) (08/14/90)

Like the subject says, I think I may be out of my league as a beginning C
programmer, but here it goes!

I am trying to write a program that will start an ftp process in the background,
write commands to the ftp's stdin and read the results from the ftp's stdout.
Circular pipes?  I'm hoping to do it entirely in C so as to avoid any shell 
programming.  I'd like to have only *one* file that does it all.  Now for
my questions:

Will a process terminate if it gets an EOF in it's stdin?  Or do I have to make
sure that my background ftp process always has something to read in?

I am trying to fork a process. (one to do the controlling, one to do the ftp)
I feel sure that the fork is working, but when I try to start ftp...well...
it never starts.  I'm lost.  What follows is the code segment in question, 
followed by the out put it generates.


#include <stdio.h>
#include <ctype.h>
#define LINE_LEN  	180
#define FTP_OUT		"Auto_ftp_out"
#define FTP_IN		"Auto_ftp_in"

char	cmd[LINE_LEN];			/* current command */

start_ftp()
{
int tmp;

sprintf(cmd,"ftp < %s > %s", FTP_IN, FTP_OUT);
puts(cmd);

if ((tmp = fork()) == -1) {
	puts("Fork could not start ftp.\n");
	exit(-1); }

printf("%d\n",tmp);

if (tmp != 0) { 	/* child process */
	puts("Starting ftp.\n");
	if (-1 == execve(cmd,cmd,"\0")) {    /* magic number from manual */
		puts("Execve could not start ftp.\n");
		exit(-1); }
	}
}

.......and now for the output....


ftp < Auto_ftp_in > Auto_ftp_out
25024
0
Starting ftp.

Execve could not start ftp.


As you can see, I do get the fork to work.....but execve() returns an error.
Any ideas?

Note that I'm a new C programmer, and that if you've read this far, I'd like
to hear any constructive comments you might have.  Helping my with this problem
would be nice, too!  ;^]

Thanx in advance.


+-------------------------+----------------------------------------------------+
|  J. Michael Diehl  ;-]  |  I thought I was wrong once.  But, I was mistaken. |
|                         +----------------------------------------------------+
|  mdiehl@hydra.unm.edu   | "I think marriage should be a lifelong commitment."|
|  Thunder@forum          |  the man said to his new wife as he placed a pistol|
|  Thunder@Tiny*          |  on the mantle.                                    |
|  (505) 272-HaHa         |                                                    |
+-------------------------+----------------------------------------------------+