Gets the value for an environment variable key.
Kernel.bdh
ProcessGetEnv( in hProc : number, in sKey : string, out sValue : string, in nValueSize : number ): boolean;
true if successful.
false in case of an error. The GetLastError function may be used to retrieve the system error code.
Parameter | Description |
---|---|
hProc | The handle that identifies the process. It is returned by the ProcessInitialize function. |
sKey | Specifies the environment variable whose value is being retrieved (e.g. "temp" or "path"). |
sValue | This parameter retrieves the value of the specified environment variable. |
nValueSize | Length of the string that receives the value for the environment variable. |
dcltrans transaction TMain var hFile : number; hProcessId : number; nStatus : number; nRead : number; sData : string; sPath : string; begin // Create process and start it up... hProcessId := ProcessInitialize("application1.exe", PROCESS_DETACHED, "", "c:\\temp\\", "c:\\temp\\out.txt"); // set environment variable "path" ProcessGetEnv(hProcessId, "path", sPath, STRING_COMPLETE); sPath := sPath + "c:\\application1\\;"; ProcessSetEnv(hProcessId, "path", sPath); RepMessage(sPath,SEVERITY_ERROR); // start the process ProcessStart(hProcessId); // Wait for process to finish Wait(25.0); // Kill the process if it hasn't finished yet nStatus := ProcessGetState(hProcessId); if (nStatus <> PROCESS_STATE_FINISHED) then ProcessKill(hProcessId, PROCESS_KILLSINGLE); end; // Read the output of the process, written to a file FOpen(hFile, "c:\\temp\\out.txt", OPT_FILE_ACCESS_READ, OPT_FILE_OPEN); while FRead(hFile, sData, 1, nRead) do Write(sData); end; FClose(hFile); ProcessFree(hProcessID); end TMain;