- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to get program A to communicate with program B (created with CreateProcess) by use of environment variables, but can't get it to work. I have been experimenting within just program A and get the following:
iret = SetEnvironmentVariable('junk','asdf')
This works fine. However, if the very next statement is:
iret = GetEnvironmentVariable('junk',temp,4)
This does not work. iret has a value of 5, and temp is blank. If the next statement after that is:
call getenv('junk',temp)
This works fine here, but it doesn't work if I place it in program B.
I guess there are a number of issues here that I don't understand, including how to use the functions, the scope of the environment variables (are they just local to one process?), and even whether this is the right approach. Also, what is the difference between Getenv and GetEnvironmentVariable? Please could someone point me to an example of a process communicating with its child.
With many thanks
Mike
iret = SetEnvironmentVariable('junk','asdf')
This works fine. However, if the very next statement is:
iret = GetEnvironmentVariable('junk',temp,4)
This does not work. iret has a value of 5, and temp is blank. If the next statement after that is:
call getenv('junk',temp)
This works fine here, but it doesn't work if I place it in program B.
I guess there are a number of issues here that I don't understand, including how to use the functions, the scope of the environment variables (are they just local to one process?), and even whether this is the right approach. Also, what is the difference between Getenv and GetEnvironmentVariable? Please could someone point me to an example of a process communicating with its child.
With many thanks
Mike
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The main thing you forgot is that all APIs require (and return) C-style, char(0) terminated strings:
(C=>F) sFortran = sC(1 : index(sC,char(0))-1)
(F=>C) sC = trim(sFortran)//char(0)
Getenv is probably just a thin wrapper around GetEnvironmentVariable, which just performs string conversion.
"Parent communicating with a child process" is a very broad description. This MSDN article is a "classic" example -- it uses pipes to redirect standard input and output; the child process may have unchanged code (i.e. retain READ(* and WRITE(* ), and the parent should be responsible to CreatePipe/WriteFile/ReadFile.
Jugoslav
(C=>F) sFortran = sC(1 : index(sC,char(0))-1)
(F=>C) sC = trim(sFortran)//char(0)
Getenv is probably just a thin wrapper around GetEnvironmentVariable, which just performs string conversion.
"Parent communicating with a child process" is a very broad description. This MSDN article is a "classic" example -- it uses pipes to redirect standard input and output; the child process may have unchanged code (i.e. retain READ(* and WRITE(* ), and the parent should be responsible to CreatePipe/WriteFile/ReadFile.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Environment variables are local to a process. When you create a child process, you can specify that the child should inherit a copy of its parent's environment variables, but it's only a copy. Changes in one after that are not seen in the other. Not an effective means of communication.
Steve
Steve

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page