The UNIX and Linux Forums  

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 02:36 AM
Advantage of executing program in user shell? seeker333 UNIX for Advanced & Expert Users 2 05-21-2008 11:19 AM
after executing execvp()... program hangs up Crab High Level Programming 3 09-21-2006 07:31 AM
Executing an .ec program in different informix versions matrixmadhan High Level Programming 0 05-21-2005 03:29 AM
executing the su command from a java program. shailendrat UNIX for Dummies Questions & Answers 1 03-24-2005 08:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-04-2002
Registered User
 

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

Read the title: how do i do it?
__________________
Go to my site... Download my Winamp3 skin... enjoy the beauty...
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-05-2002
Registered User
 

Join Date: Nov 2001
Posts: 33
Stumble this Post!
$ man exec
or execv etc
Reply With Quote
  #3 (permalink)  
Old 02-05-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
You also might want to look at "man system" and "man popen".
Reply With Quote
  #4 (permalink)  
Old 02-06-2002
Registered User
 

Join Date: Feb 2002
Posts: 1
Stumble this Post!
sample source

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

if (!fork()) {
execvp(arguments[0],arguments);
exit(-1);
} else {
result=wait(&status);
...
}
__________________
shame on me 8-)
Reply With Quote
  #5 (permalink)  
Old 06-27-2002
Registered User
 

Join Date: Jun 2002
Location: Warrensburg, MO
Posts: 2
Stumble this Post!
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; 
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0