export variables to launched process?
ambassador at fourthworld.com
Thu Feb 4 10:33:41 EST 2016
Mark Waddingham wrote:
> On 2016-02-04 02:57, Richard Gaskin wrote:
>> I've successfully exported variables to a process run with shell,
>> put shell("export somevar='Hello!'; ./test.sh")
>> ...where test.sh simply echoes somevar to verify that it got it.
>> Now I have a process I need to read and write to, but I don't know
>> how to export variables to it - clues?
> A process that gets launched either via shell or open process will
> inherit the environment variables set by the engine... So I think
> put "Hello!" into $somevar
> put shell("./test.sh")
> open process ... for ...
> Should both have the effect that the launched process will see
> 'somevar' as specified.
Indeed it does. I had thought that was how it should work, but
apparently I had a problem in the bash script I was running as the
launched process, and that led me astray.
So simple! Nice. Will that work on Windows as well?
Here's what I'm up to: I've been writing a simple HTTP server for local
testing of web stuff, particularly CGIs like LC Server and standalones
made with LC run with -ui.
With variable exporting I can recreate pretty much all the things a CGI
needs from the Apache environment, with one exception which is my next
task: POST data.
When running a CGI that uses POST, the CGI will read stdin to obtain the
POST data. My understanding is that LC Server does this for us and puts
the parsed data into the array $_POST, as does PHP. But other CGIs,
like standalones or bash scripts or others that don't offer that
convenience, the process will need to read stdin to obtain that data.
So my aim is to open the CGI process for append, write the POST data
that I'd previously read from the socket to the opened process, read
whatever comes back, and then close it and return the processes' output
back over the socket to the client.
For GET this is working now using "shell"; I haven't used "open process"
in so long that I have no experience with how reading and writing work
with regard to stdin in the child.
I should have some time to experiment with that later today, but if you
know of any reason why that won't work your input would be very helpful.
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the Use-livecode