Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-08

set envirom variable with pascal in linux

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

mondrillo

Hello list,

In Bach, Perl, can do set SDL_VER=`sdl-config --version` and in enviroment has the variable SDL_VER=1.2.3 for example. echo $SDL_VER
1.2.3
But in Pascal non have the setenv() procedure as in C :(

Actualy I resolve this problem with sending the output to a file, and then reading the file. But, can I pass from C this function?, or call a libc (thinks is this lib that has setenv() ) from Pascal to execute setenv().

Thank's and regards.

Michael Van Canneyt
to mondrillo
mondrillo wrote 12 lines
Hello list, In Bach, Perl, can do set SDL_VER=`sdl-config --version` and in enviroment has the variable SDL_VER=1.2.3 for example. echo $SDL_VER 1.2.3 But in Pascal non have the setenv() procedure as in C :( Actualy I resolve this problem with sending the output to a file, and then reading the file. But, can I pass from C this function?, or call a libc (thinks is this lib that has setenv() ) from Pascal to execute setenv().

That will not work.

FPC has a copy of the environment, which it received on startup. It makes little or no sense to add strings to this, since it is for internal use only.

If you want to execute another program with a different set of environment strings, you must use the execve call to specify a different set of environment variables.

The TProcess component allows you to easily specify the environment as a TStringList.

Michael.

Alain Vitry
to mondrillo: In Bach, Perl, can do set SDL_VER=`sdl-config --version` and in enviroment has the…

FYI, see
http://alain.vitry.free.fr/en/devel/devel-pascal.php

mondrillo wrote 20 lines
Hello list, In Bach, Perl, can do set SDL_VER=`sdl-config --version` and in enviroment has the variable SDL_VER=1.2.3 for example. echo $SDL_VER 1.2.3 But in Pascal non have the setenv() procedure as in C :( Actualy I resolve this problem with sending the output to a file, and then reading the file. But, can I pass from C this function?, or call a libc (thinks is this lib that has setenv() ) from Pascal to execute setenv(). Thank's and regards. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marc Santhoff
to mondrillo: In Bach, Perl, can do set SDL_VER=`sdl-config --version` and in enviroment has the…
mondrillo wrote 13 lines
Hello list, In Bach, Perl, can do set SDL_VER=`sdl-config --version` and in enviroment has the variable SDL_VER=1.2.3 for example. echo $SDL_VER 1.2.3 But in Pascal non have the setenv() procedure as in C :( Actualy I resolve this problem with sending the output to a file, and then reading the file. But, can I pass from C this function?, or call a libc (thinks is this lib that has setenv() ) from Pascal to execute setenv().

If you're using a command line to execute a foreign program you can always tell the shell:

csh: "setenv VAR value; your-foreign-program"
sh: "VAR=value; your-foreign-program"

Not portable, ugly workaround, but it does do the job.

HTH,
Marc

Jeff Pohlmeyer
Show quoted text 5 lines
In Bach, Perl, can do set SDL_VER=`sdl-config --version` But in Pascal non have the setenv() procedure as in C :( ... Actualy I resolve this problem with sending the output to a file, and then reading the file.

It sounds to me like you just want a global
variable, not an environment variable.

Maybe something like this?

(************************************)
program sdlver;
uses libc;
type
SDL_version = record
major : byte;
minor : byte;
patch : byte;
end;
pSDL_version = ^SDL_version;
function SDL_Linked_Version:pSDL_version; cdecl; external 'SDL';
var
SDL_VER:array[0..15] of char;
begin
with SDL_Linked_Version^ do sprintf(SDL_VER, '%d.%d.%d', [major, minor,
patch]);
WriteLn(SDL_VER);
end.
(************************************)

Regards,
- Jeff

mondrillo
to Marc Santhoff: If you're using a command line to execute a foreign program you can always tell the shell:

Thanks, is the only think that I probe and runs ok!!!

****
program shell2;
uses baseunix, sysutils;
begin
    writeln('glx-config Version:',fpGetenv('SDL_VER'));
end.
****

export SDL_VER=`sdl-config --version`; ./shell2
glx-config Version:1.2.8

Note. I have put the clause EXPORT because I'm using bash.

I don't probe tu use the other method that other person has posted than use a call to glibc, perhaps it's the largest walk.

Another one, has mentioned than FreePascal(FP) gives an enviroment in read-only, I have read that the environ is an array of list of var's with values, and I'dont know why FP (I love it) cannot write in this array, perhaps do not implement yet.

Thank's eveybody, and regards.

Marc Santhoff wrote 31 lines
Am Dienstag, den 30.08.2005, 08:47 +0200 schrieb mondrillo: > Hello list, > > In Bach, Perl, can do set SDL_VER=`sdl-config --version` > and in enviroment has the variable SDL_VER=1.2.3 for example. > echo $SDL_VER > 1.2.3 > But in Pascal non have the setenv() procedure as in C :( > > Actualy I resolve this problem with sending the output to a file, and > then reading the file. But, can I pass from C this function?, or call > a libc (thinks is this lib that has setenv() ) from Pascal to execute > setenv(). > If you're using a command line to execute a foreign program you can always tell the shell: csh: "setenv VAR value; your-foreign-program" sh: "VAR=value; your-foreign-program" Not portable, ugly workaround, but it does do the job. HTH, Marc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
mondrillo
to Alain Vitry: FYI, see http://alain.vitry.free.fr/en/devel/devel-pascal.php

Thank's for the page

Alain Vitry wrote 30 lines
FYI, see http://alain.vitry.free.fr/en/devel/devel-pascal.php Le 30 août 05, à 08:47, mondrillo a écrit : > Hello list, > > In Bach, Perl, can do set SDL_VER=`sdl-config --version` > and in enviroment has the variable SDL_VER=1.2.3 for example. > echo $SDL_VER > 1.2.3 > But in Pascal non have the setenv() procedure as in C :( > > Actualy I resolve this problem with sending the output to a file, and > then reading the file. But, can I pass from C this function?, or call > a libc (thinks is this lib that has setenv() ) from Pascal to execute > setenv(). > > Thank's and regards. > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
mondrillo
to Jeff Pohlmeyer: It sounds to me like you just want a global variable, not an environment variable. Maybe…

Thank's for the response, perhaps it's my arch ( amd64 ) and compiler 2.0.0, but when I execute this code say :

./sdlver
1.5426178.-248

if I execute `$sdl-config --version` output is not the same :( 1.2.8

Jeff Pohlmeyer wrote 42 lines
> In Bach, Perl, can do set SDL_VER=`sdl-config --version` > But in Pascal non have the setenv() procedure as in C :( > ... > Actualy I resolve this problem with sending the output to a file, and > then reading the file. It sounds to me like you just want a global variable, not an environment variable. Maybe something like this? (************************************) program sdlver; uses libc; type SDL_version = record major : byte; minor : byte; patch : byte; end; pSDL_version = ^SDL_version; function SDL_Linked_Version:pSDL_version; cdecl; external 'SDL'; var SDL_VER:array[0..15] of char; begin with SDL_Linked_Version^ do sprintf(SDL_VER, '%d.%d.%d', [major, minor, patch]); WriteLn(SDL_VER); end. (************************************) Regards, - Jeff