Forum > Operating Systems

Executing shell commande on UNIX FreeBSD

(1/1)

BSaidus:
I have an issue with executing commande for setting an environnement variable on FreeBSD ( shell is csh )
the commande is :

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  setenv PARAM_1 152100 Directelly on shell it executes well, but in freepascal, It do not.
I tried all functions on process and unix units.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// not workRunCommand( '/bin/csh', ['-c', 'setenv PARAM_1 152100'],s); // s an Ansistring // Not work  with TProcess.Create(nil) do  begin    try      Executable := '/bin/csh';      //CommandLine := 'setenv PARAM_1 152100';      Options := Options + [poWaitOnExit];      Parameters.Clear;      Parameters.Add('-c');      Parameters.Add('setenv');       //Parameters.Add('-c setenv PARAM_1 152100');      //Parameters.Add('setenv PARAM_1 152100');      Parameters.Add('PARAM_1');      Parameters.Add('152100');      Execute;    finally      Free;    end;  end;  
So , Can Anyone help me ???

Thanks.

MarkMLl:
Won't work. You can only set a shell variable applying to the current process on unix.

DOS etc. had a backdoor to allow a child process to set an environment variable in its parent command.com etc., so if you find somebody saying OF COURSE this works be cautious. Even in this case there were limits based on how much memory was allocated.

I've got round this in the past by having layered programs, i.e. the shell, then a custom program, then a second shell which inherits variables.

MarkMLl

BSaidus:

--- Quote from: MarkMLl on January 04, 2021, 06:12:17 pm ---Won't work. You can only set a shell variable applying to the current process on unix.

DOS etc. had a backdoor to allow a child process to set an environment variable in its parent command.com etc., so if you find somebody saying OF COURSE this works be cautious. Even in this case there were limits based on how much memory was allocated.

I've got round this in the past by having layered programs, i.e. the shell, then a custom program, then a second shell which inherits variables.

MarkMLl

--- End quote ---

Thank you @MarkMLl,
i will proceed in other way.

MarkMLl:
Apologies for posting to a fairly old thread.

This https://hackaday.com/2019/12/30/linux-fu-leaning-down-with-exec/ hence https://www.drdobbs.com/shell-corner-bash-dynamically-loadable-b/199102950 discusses writing shell extensions for Bash.

With the important caveat that I've not tried this (and don't know whether using FPC would be problematic), in principle it might be possible to write a shell extension that listened to a unix-domain socket, and on receipt of a message changed a shell/environment variable.

The result of this would be that the next program started by that shell would see the changed variable, which is something which cannot normally be done since a child cannot access a parent's memory.

MarkMLl

Navigation

[0] Message Index

Go to full version