LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-04-2008, 06:00 AM   #1
carlcs
LQ Newbie
 
Registered: Apr 2008
Posts: 14

Rep: Reputation: 0
stdout and cgi problem


Hello! Anyone.

I'm writing a web server. I don't know how to transfer the content entity which implement by POST to CGI program. It's about the detail of implementation. the develop language is C.

I kinda confuse how stdout or stdin work? CGI program can get the data from stdin and put the data to stdout. How can I put the data to stdin using C. When the CGI program put the data to stdout, it just use "printf". How can I capture the data from stdout?


Can anyone explain how stdout or stdin work? Is cgi program can attain stdout correctly when i use muti-thread programming?

Thanks.

Last edited by carlcs; 05-04-2008 at 03:55 PM.
 
Old 05-04-2008, 06:33 AM   #2
seraphim172
Member
 
Registered: May 2008
Posts: 101

Rep: Reputation: 15
hmm

If your webserver is going to support standard behaviour, then you have to split the POST options from the URL. So everything after the question mark becomes a list of key-value pairs separated by '&', like:

Code:
www.domain.com/my.php?a=1&b=2
You will get www.domain.com/my.php as the base URL, your server has to figure out it's a PHP file, then split the key-value pairs into "a=1", "b=2", etc.

You will then call PHP (note the translation from web URL to local filesystem path) with a system call like
Code:
php /var/www/html/virtual.domain.com/my.php "a=1" "b=2"
or
Code:
php /var/www/html/virtual.domain.com/my.php "a" "1" "b" "2"
The examples above are simple but actually quite useless, because each PHP script would have to either split keys from values or assume keys and values follow each other in strict order.

A nice feature would be a PHP module in your server that sets up an $_REQUEST correctly, like
Code:
$_REQUEST['a'], $_REQUEST['b']
If you've done all that, you still only handled PHP. Do the same for Perl, Python, or whatever script you want to support.

The basic concept of a webserver is not complicated, but the implementation certainly will be. Is there a specific reason why you are not using Apache, Lighttpd or Tux?

Linux Archive

Last edited by seraphim172; 06-05-2008 at 10:36 AM.
 
Old 05-04-2008, 04:01 PM   #3
carlcs
LQ Newbie
 
Registered: Apr 2008
Posts: 14

Original Poster
Rep: Reputation: 0
I changed my question, Please look again.

Actually, i'm practising my programming skill. My web server is just a little project. My main language is C. It's quite too hard for me , but worth.

I'm acquainted with the concept of web server, so does the HTTP protocol. I'm using C. I knew how to get and split the data which read from stdin. I just don't know ... Please look my question again. Hope for your answer, Thank you.
 
  


Reply

Tags
cgi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tr, sed, and strange stdout problem d1s4st3r Programming 7 01-24-2008 10:01 PM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 02:36 AM
problem in restoring stdout to default user_linux Linux - Newbie 2 08-22-2005 02:21 PM
CGI programming & stdout nodger Programming 1 04-09-2005 11:00 AM
#@!?£$# stdout problem!! beedyrazzle Linux - Newbie 3 01-21-2003 08:03 PM


All times are GMT -5. The time now is 05:28 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration