Sponsored Content
Top Forums Programming executing a program within a program Post 23707 by hirni on Thursday 27th of June 2002 03:36:25 PM
Old 06-27-2002
fork/execv in CGI

I'm having a couple of problems with my CGI program.

First, I don't know how to get [the text our getfacl program would create] back so I can return it to a web browser. I was hoping that, since getfacl program writes to standard output, that it would just be written back to the browser (or to standard output) when called from within the hello.cgi program.

Secondly, the fork command doesn't seem to work the same for a CGI program.

When I call the program from the prompt (it's called hello.cgi), everything comes out as expected...
Code:
bash-2.05$ ./hello.cgi
Content-type: text/html

waiting<br>
calling getfacl<br>called getfacl<br>done waiting<br>

but when I hit it with the web browser, what comes back is:
Code:
Content-type: text/html

calling getfacl<br>called getfacl<br>Content-type: text/html

waiting<br>
done waiting<br>

which almost seems as though it's returning the output from one process at a time... first the child process, then the parent process.

So, my two questions are:
  • How do I get the text [the program I'm calling with execv] would normally write to stdout
  • How come it's right when I execute hello.cgi from the command line, but all jumbled up when I run it through cgi

By the way, I guess I should mention that it's running through apache 1.3.20 on red had linux. Wish I knew how to get the Linux version, but...

Although I understand the concepts fairly well, I've got almost no experience with fork or the exec family (and only a little UNIX/Linux experience),

The hello.cgi code is below. Any help would be greatly appreciated.


Code:
#include <stdio.h>

int main (int argc, char *argv[])
{
  int result,stat;
  char *args[]={"getfacl", ".", 0};
  
  printf("Content-type: text/html\n\n"); 
  
  if (fork()) {
    printf("waiting<br>\n");
    result=wait(&stat);
    printf("done waiting<br>\n");
  } else {
    printf ("calling getfacl<br>");
    execv ("getfacl", args);
    printf ("called getfacl<br>");
    exit(-1);
  }
  
  printf ("\n");
  
  return 0; 
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

executing the su command from a java program.

Say in unix (AIX) m/c, I am logged in with s1 user and want to start process p1 with user credentials of s2. I can do manually in this way: #su - s2 #enter password for s2> somePassword $ p1 But all this I have to do through a java program. How to pass the password through program. One... (1 Reply)
Discussion started by: shailendrat
1 Replies

2. Programming

Executing an .ec program in different informix versions

Hi all, I tried writing an .ec program connecting to informix database from solaris platform Sun 5.7 informix version that i had to used when i compiled the program was 9.21.UC3 the binary when i ported solaris box with informix version 9.40.UC5 i am unable to run that i am encountering... (0 Replies)
Discussion started by: matrixmadhan
0 Replies

3. Programming

after executing execvp()... program hangs up

Hi , I m actually trying to implement pipes program,but after executing the execvp(),my program is getting hanged up :mad: Actaully i m getting the desired output expected from execvp()...but once results are displayed on the output screen ,program is getting hanged up values of... (3 Replies)
Discussion started by: Crab
3 Replies

4. Programming

Trubble in executing the cpp program...

I wrote a code like this....... #include <iostream> #include <stdio.h> #include <mysql.h> #include <string.h> #include <stdlib.h> using namespace std; #include "Connection.h" int main() { char *Host = (char *)"localhost"; char *Database =(char *)"sachin"; char... (3 Replies)
Discussion started by: ps_sach
3 Replies

5. Solaris

How to know the size of the program currently executing in memory

hey everybody, i am currently working on solaris 10 os on a m5000 server. my problem is when i want the exact size of a program in execution, i am unable to do it. earlier i thought the RSS field of prstat but because of its large size it cant be the size. pmap -x shows some output but it includes... (2 Replies)
Discussion started by: aryansheikh
2 Replies

6. Shell Programming and Scripting

Executing a Java Program

I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

7. Shell Programming and Scripting

Executing WIN32OLE program

Hello, Please help me out to execute this perl program: #!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... # get already active Excel application or open new my... (6 Replies)
Discussion started by: suvenduperl
6 Replies

8. UNIX for Dummies Questions & Answers

executing a different program

What system calls or commands do I need to use in order to execute a different program from an already running process? (1 Reply)
Discussion started by: justOne21
1 Replies

9. Shell Programming and Scripting

AWK Program Not Executing On Linux with KSH

Overview: I have an AWK program that parses thru a database backup server log file and outputs ths following parameters SRNO DATE : TIME SIZE IN(KB) DATABASE NAME DUMP TYPE 1 May 16 2012: 13:30:00 6874 TestDB database 2 May 16 2012: 13:30:44 11462 master database Problem: This program has... (5 Replies)
Discussion started by: JolietJake
5 Replies

10. Programming

Error in executing the C program

Hello Friends, I have written a code for the unisex bathroom which makes a policy that when a woman is in the bathroom only other women may enter, but not men, and vice versa. This program consists of four functions which a user defines but these functions are not properly working while... (4 Replies)
Discussion started by: Ravi Tej
4 Replies
KXTERM(1)						      General Commands Manual							 KXTERM(1)

NAME
kxterm - the CERN KUIP terminal emulator SYNOPSIS
kxterm [class] [options] DESCRIPTION
kxterm is a terminal emulator combining the best features of the (now defunct) Apollo DM pads (like: input and transcript pads, automatic file backup of transcript pad, string search in pads, etc.) and the Korn shell emacs-style command line editing and command line recall mechanism. For more detailed information about the program, please see the online help available from the kxterm Help menu. kxterm has a number of X resources which can be set by the user; these are listed in the online help and in the file /etc/X11/app-defaults/KXterm, where the default values are set. It should be noted that when kxterm is acting as a client for another application, the desired X resource should be prefixed by "Kx" plus the class name of the application. So for application "Foo" the kxterm resource class would be KxFoo, and one would set KxFoo*background, etc. One can also set the resource class of a kxterm window via the command-line with the class argument. OPTIONS
-font fn Specifies the font used by kxterm. The font fn must be an XLFD (X Logical Font Description), as for example displayed by the xls- fonts program. -geometry geom Specifies the preferred size and position of the kxterm window; see X(7x) for details. -h, -help Show a summary of options. -iconic Specifies that the window manager should start kxterm as an icon. -n iconname Specifies the name of the kxterm window in an iconic state. -name name Specifies both the title and the iconized name of the kxterm window. -pid pid Specifies the process ID of the program that kxterm should act as a client for. -prompt prompt Sets the prompt displayed in the input pad of the program. -tfont fn Specifies the font used by text boxes, the input pad, and the transcript pad of the program. This should probably be a fixed-width font like "courier" or "fixed". -title title Sets the title of the kxterm window to title. SEE ALSO
o xlsfonts(1) - a program to list available fonts on an X server o paw++(1) - a program using kxterm for its command interface o the online help available from kxterm's Help menu AUTHOR
This manual page was written by Kevin McCarty <kmccarty@debian.org> for the Debian GNU/Linux system (but may be used by others). January 24, 2003 KXTERM(1)
All times are GMT -4. The time now is 04:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy