The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Executing shell program from a web page venkatritch Shell Programming and Scripting 5 06-14-2008 05:36 AM
Advantage of executing program in user shell? seeker333 UNIX for Advanced & Expert Users 2 05-21-2008 02:19 PM
after executing execvp()... program hangs up Crab High Level Programming 3 09-21-2006 10:31 AM
Executing an .ec program in different informix versions matrixmadhan High Level Programming 0 05-21-2005 06:29 AM
executing the su command from a java program. shailendrat UNIX for Dummies Questions & Answers 1 03-24-2005 12:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-05-2002
Gekko Gekko is offline
Registered User
  
 

Join Date: Jan 2002
Location: @ my computer... duh
Posts: 8
executing a program within a program

Read the title: how do i do it?
  #2 (permalink)  
Old 02-05-2002
thalex thalex is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 33
$ man exec
or execv etc
  #3 (permalink)  
Old 02-05-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
You also might want to look at "man system" and "man popen".
  #4 (permalink)  
Old 02-06-2002
bangieff bangieff is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 1
sample source

char **arguments;
int result,status;
....

if (!fork()) {
execvp(arguments[0],arguments);
exit(-1);
} else {
result=wait(&status);
...
}
  #5 (permalink)  
Old 06-27-2002
hirni hirni is offline
Registered User
  
 

Join Date: Jun 2002
Location: Warrensburg, MO
Posts: 2
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; 
}
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0