set envirom variable with pascal in linux

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

set envirom variable with pascal in linux

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.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: set envirom variable with pascal in linux

Michael Van Canneyt


On Tue, 30 Aug 2005, mondrillo wrote:

> 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.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: set envirom variable with pascal in linux

Alain Vitry
In reply to this post by mondrillo
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  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: set envirom variable with pascal in linux

Marc Santhoff
In reply to this post by mondrillo
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  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: set envirom variable with pascal in linux

Jeff Pohlmeyer
In reply to this post by mondrillo

> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: set envirom variable with pascal in linux

mondrillo
In reply to this post by Marc Santhoff
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.



El mar, 30-08-2005 a las 14:53 +0200, Marc Santhoff escribió:

> 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  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: set envirom variable with pascal in linux

mondrillo
In reply to this post by Alain Vitry
Thank's for the page

El mar, 30-08-2005 a las 12:16 +0200, Alain Vitry escribió:

> 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  -  [hidden email]
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> >
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: set envirom variable with pascal in linux

mondrillo
In reply to this post by Jeff Pohlmeyer
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


El mar, 30-08-2005 a las 08:23 -0500, Jeff Pohlmeyer escribió:

>
> > 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
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal