Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Writing CGI using UNIX-C

1 view
Skip to first unread message

pei pei

unread,
Dec 27, 1998, 3:00:00 AM12/27/98
to
How can a cgi program call another C program...
the cgi is written using unix-c....
Can I use popen, exec or other?
But when i used exec, my program will always core dump why?


I hope someone could give me the solutions... it is very urgent coz i have
to hand out my project soon... i have tried so many alternative ways but
failed...
Thanks for your help...


Lawrence Kirby

unread,
Dec 27, 1998, 3:00:00 AM12/27/98
to
In article <01be31ab$2e01ef80$7db8...@caryn75.tm.net.my>
car...@tm.net.my "pei pei" writes:

>How can a cgi program call another C program...
>the cgi is written using unix-c....
>Can I use popen, exec or other?
>But when i used exec, my program will always core dump why?

The standard C library provides only one function to run another program
(or system command) and that is system(). Anything else is platform-
specific. The best place to discuss popen, exec*() etc. is
comp.unix.programmer.

--
-----------------------------------------
Lawrence Kirby | fr...@genesis.demon.co.uk
Wilts, England | 7073...@compuserve.com
-----------------------------------------


F. Paul Menard

unread,
Dec 30, 1998, 3:00:00 AM12/30/98
to
All,

Following is from MS C++ 5.0. I think MOST C cpoilers support the exec*
family of functions.

_execl, _wexecl
Load and execute new child processes.

int _execl( const char *cmdname, const char *arg0, ... const char *argn,
NULL );

int _wexecl( const wchar_t *cmdname, const wchar_t *arg0, ... const wchar_t
*argn, NULL );

Function
Required Header
Optional Headers
Compatibility

_execl
<process.h>
<errno.h>
Win 95, Win NT

_wexecl
<process.h> or <wchar.h>
<errno.h>
Win NT

For additional compatibility information, see Compatibility in the
Introduction.

Libraries

LIBC.LIB
Single thread static library, retail version

LIBCMT.LIB
Multithread static library, retail version

MSVCRT.LIB
Import library for MSVCRT.DLL, retail version

Return Value

If successful, these functions do not return to the calling process. A
return value of –1 indicates an error, in which case the errno global
variable is set.

errno Value
Description

E2BIG
The space required for the arguments and environment settings exceeds 32K.

EACCES
The specified file has a locking or sharing violation.

EMFILE
Too many files open (the specified file must be opened to determine whether
it is executable).

ENOENT
File or path not found.

ENOEXEC
The specified file is not executable or has an invalid executable-file
format.

ENOMEM
Not enough memory is available to execute the new process; or the available
memory has been corrupted; or an invalid block exists, indicating that the
calling process was not allocated properly.

Parameters

cmdname Path of file to be executed

arg0, ... argn List of pointers to parameters

Remarks

Each of these functions loads and executes a new process, passing each
command-line argument as a separate parameter.

Example


/* EXEC.C illustrates the different versions of exec including:
* _execl _execle _execlp _execlpe
* _execv _execve _execvp _execvpe
*
* Although EXEC.C can exec any program, you can verify how
* different versions handle arguments and environment by
* compiling and specifying the sample program ARGS.C. See
* SPAWN.C for examples of the similar spawn functions.
*/

#include <stdio.h>
#include <conio.h>
#include <process.h>

char *my_env[] = /* Environment for exec?e */
{
"THIS=environment will be",
"PASSED=to new process by",
"the EXEC=functions",
NULL
};

void main()
{
char *args[4], prog[80];
int ch;

printf( "Enter name of program to exec: " );
gets( prog );
printf( " 1. _execl 2. _execle 3. _execlp 4. _execlpe\n" );
printf( " 5. _execv 6. _execve 7. _execvp 8. _execvpe\n" );
printf( "Type a number from 1 to 8 (or 0 to quit): " );
ch = _getche();
if( (ch < '1') || (ch > '8') )
exit( 1 );
printf( "\n\n" );

/* Arguments for _execv? */
args[0] = prog;
args[1] = "exec??";
args[2] = "two";
args[3] = NULL;

switch( ch )
{
case '1':
_execl( prog, prog, "_execl", "two", NULL );
break;
case '2':
_execle( prog, prog, "_execle", "two", NULL, my_env );
break;
case '3':
_execlp( prog, prog, "_execlp", "two", NULL );
break;
case '4':
_execlpe( prog, prog, "_execlpe", "two", NULL, my_env );
break;
case '5':
_execv( prog, args );
break;
case '6':
_execve( prog, args, my_env );
break;
case '7':
_execvp( prog, args );
break;
case '8':
_execvpe( prog, args, my_env );
break;
default:
break;
}

/* This point is reached only if exec fails. */
printf( "\nProcess was not execed." );
exit( 0 );
}

Process and Environment Control Routines | _exec, _wexec_Function Overview

See Also abort, atexit, exit, _onexit, _spawn Function Overview, system


FPM


pei pei wrote in message <01be31ab$2e01ef80$7db8...@caryn75.tm.net.my>...


>How can a cgi program call another C program...
>the cgi is written using unix-c....
>Can I use popen, exec or other?
>But when i used exec, my program will always core dump why?
>
>

0 new messages