![]() |
|
#1
|
|||
|
|||
How to "get" environment variablesHi , this is probably dumb but I can't think of anything and you guys are hungry! so
How can I get a value from my shell into my program? CPP / C++ / C Code:
Code:
I guess system("echo blah"); goes to stdout. Should I try to "catch" that? or would I need to pipe data or something like that? Ultimately I am trying to handle simple html <form method='get' action='../cgi-bin/blah.bin.> data. It comes in appended to the url and the server stores it in the env variable "QUERY_STRING". I want to C how it REALLY works... php... bah! Thanks |
|||
|
#2
|
|||
|
|||
Re: how to "get" environment variablesQuote:
The non-standard library function getenv() is supplied with GNU compiler implementations. CPP / C++ / C Code:
Code:
... Quote:
If you cast the return value to a pointer to char and then dereference it (by sprintf, for example) the program crashes. Regards, Dave Footnote: I said that the return value from system("echo anything") is zero, and here's why: In fact, in Linux the system command executes a fork(), and returns a value of -1 if the fork fails. If the fork is successful, it returns a value from the "anything" command. Assuming that "echo" is the program supplied with your operating system, Is there any way that a fork to "echo" can fail? Is there any argument that you can give to the echo command that makes "echo" return anything other than zero? I don't either of these can happen, but ... Last edited by davekw7x : 12-Sep-2009 at 10:23.
|
|
#3
|
|||
|
|||
Re: how to "get" environment variablesQuote:
I wonder where my head was at. I should have said that getenv is a C and C++ standard library function. Everyone can play. Oh, well... Regards, Dave |
|
#4
|
|||
|
|||
Re: how to "get" environment variablesThanks Dave.
re: non-standard getenv() - Glad you clarified that , I was going to ask... getenv() is doing the trick alright. I have put together the beginings of my C form handler which is working on my install of apache. I included some setup information as well for anyone interested in giving it a try. CPP / C++ / C Code:
Thanks again; Howard++; |
|
#5
|
|||
|
|||
Re: how to "get" environment variablesAnd the method="post" is easy to get too:
CPP / C++ / C Code:
|
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Global Variables | Kalvorod | C++ Forum | 11 | 21-Feb-2007 12:07 |
| Local variables unknown ! | jvpic | C++ Forum | 3 | 10-Aug-2006 09:21 |
| How do you SAFELY pass hidden variables through merchant account payment screens? | mrsurrey | eCommerce / Merchant Account Forum | 4 | 03-Jul-2006 15:28 |
| variables return to previous value after i try to set them | nasaiya | MS Visual C++ / MFC Forum | 2 | 14-Jun-2005 00:43 |
| [Tutorial] Pointers in C (Part I) | Stack Overflow | C Programming Language | 1 | 08-Apr-2005 18:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The