[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Ignoring RUBYOPT ?

e

1/17/2005 10:32:00 PM


> Lähettäjä: "Erik Veenstra" <google@erikveen.dds.nl>
> Aihe: Re: Ignoring RUBYOPT ?
>
> > How can I let Ruby ignore RUBYOPT?
> >
> > Both -T1 and unsetting the environment variable aren't
> > possible in my situation. I don't want the rest of the script
> > to run in safe mode 1 and I don't have control of the
> > environment...
>
> No solutions? Anybody?

I haven't followed this thread, but since the internal ENV only
affects the current process and its children, can you wrap your
program in a script that unsets RUBYOPT and then just fork/popen
the real program?

> gegroet,
> Erik V.

E



18 Answers

Erik Veenstra

1/17/2005 11:27:00 PM

0

> > How can I let Ruby ignore RUBYOPT?
> >
> > Both -T1 and unsetting the environment variable aren't
> > possible in my situation. I don't want the rest of the
> > script to run in safe mode 1 and I don't have control of
> > the environment...
>
> I haven't followed this thread, but since the internal ENV
> only affects the current process and its children, can you
> wrap your program in a script that unsets RUBYOPT and then
> just fork/popen the real program?

No, I can't. I start ruby.exe from a little FreePascal program,
which does have getenv(), but no such thing as setenv().

Using an intermediate .bat file isn't an option, because I
don't want a stupid DOS-box when using rubyw.exe instead of
ruby.exe.

Mmhh... I might use an intermediate Ruby script to unset the
environment variable... Not pretty, but it might work....
gegroet,
Erik V.

Gennady

1/17/2005 11:38:00 PM

0

Erik Veenstra wrote:
>>>How can I let Ruby ignore RUBYOPT?
>>>
>>>Both -T1 and unsetting the environment variable aren't
>>>possible in my situation. I don't want the rest of the
>>>script to run in safe mode 1 and I don't have control of
>>>the environment...
>>
>>I haven't followed this thread, but since the internal ENV
>>only affects the current process and its children, can you
>>wrap your program in a script that unsets RUBYOPT and then
>>just fork/popen the real program?
>
>
> No, I can't. I start ruby.exe from a little FreePascal program,
> which does have getenv(), but no such thing as setenv().

Have you checked for putenv()?

>
> Using an intermediate .bat file isn't an option, because I
> don't want a stupid DOS-box when using rubyw.exe instead of
> ruby.exe.
>
> Mmhh... I might use an intermediate Ruby script to unset the
> environment variable... Not pretty, but it might work....
> gegroet,
> Erik V.
>
>



Erik Veenstra

1/17/2005 11:51:00 PM

0

> > > > How can I let Ruby ignore RUBYOPT?
> > > >
> > > > Both -T1 and unsetting the environment variable aren't
> > > > possible in my situation. I don't want the rest of the
> > > > script to run in safe mode 1 and I don't have control
> > > > of the environment...
> > >
> > > I haven't followed this thread, but since the internal
> > > ENV only affects the current process and its children,
> > > can you wrap your program in a script that unsets RUBYOPT
> > > and then just fork/popen the real program?
> >
> > No, I can't. I start ruby.exe from a little FreePascal
> > program, which does have getenv(), but no such thing as
> > setenv().
>
> Have you checked for putenv()?

Briliant idea! And yes, I've checked it. And no, it doesn't
exist...

gegroet,
Erik V.

Erik Veenstra

1/17/2005 11:52:00 PM

0

> > > > How can I let Ruby ignore RUBYOPT?
> > > >
> > > > Both -T1 and unsetting the environment variable aren't
> > > > possible in my situation. I don't want the rest of the
> > > > script to run in safe mode 1 and I don't have control
> > > > of the environment...
> > >
> > > I haven't followed this thread, but since the internal
> > > ENV only affects the current process and its children,
> > > can you wrap your program in a script that unsets RUBYOPT
> > > and then just fork/popen the real program?
> >
> > No, I can't. I start ruby.exe from a little FreePascal
> > program, which does have getenv(), but no such thing as
> > setenv().
>
> Have you checked for putenv()?

Brilliant idea! And yes, I've checked it. And no, it doesn't
exist...

gegroet,
Erik V.

Gennady

1/18/2005 12:07:00 AM

0

Erik Veenstra wrote:
>>>>>How can I let Ruby ignore RUBYOPT?
>>>>>
>>>>>Both -T1 and unsetting the environment variable aren't
>>>>>possible in my situation. I don't want the rest of the
>>>>>script to run in safe mode 1 and I don't have control
>>>>>of the environment...
>>>>
>>>>I haven't followed this thread, but since the internal
>>>>ENV only affects the current process and its children,
>>>>can you wrap your program in a script that unsets RUBYOPT
>>>>and then just fork/popen the real program?
>>>
>>>No, I can't. I start ruby.exe from a little FreePascal
>>>program, which does have getenv(), but no such thing as
>>>setenv().
>>
>>Have you checked for putenv()?
>
>
> Briliant idea! And yes, I've checked it. And no, it doesn't
> exist...
>
> gegroet,
> Erik V.
>
>

I can smell a kind of sarcasm here ;-). Anyways, you are welcome.

You can also see into how you launch your ruby from FreePascal, some
exec variants, like execve(), provide the ability to specify
environment for a program you launch. I now recall this mentioned on
some FreePascal forums. (Disclaimer: I do not know FreePascal, I do not
program in Windows).

Sorry if it is of no help either,
Gennady.


Erik Veenstra

1/18/2005 12:46:00 AM

0

> > > Have you checked for putenv()?
> >
> > Briliant idea! And yes, I've checked it. And no, it doesn't
> > exist...
>
> I can smell a kind of sarcasm here ;-). Anyways, you are
> welcome.

Sorry... ;-)

> You can also see into how you launch your ruby from
> FreePascal, some exec variants, like execve(), provide the
> ability to specify environment for a program you launch. I
> now recall this mentioned on some FreePascal forums.
> (Disclaimer: I do not know FreePascal, I do not program in
> Windows).

execve is part of the Linux unit and of no use for us. There's
no equivalent in the Windows world. Some time ago, I switched
from exec of the Dos unit to executeprocess of the SysUtils
unit, because of the length of the command line (~4000 instead
of 255).

The problem with RUBYOPT is easily solved in the Linux universe
by executing a shell script in which RUBYOPT is set to nothing
before launching Ruby. There are no irritating DOS-box popping
up here. (It wouldn't be called "DOS-bos", anyway...) The
problem is really a problem in the Windows world. And it's
exactly the latter that has no execve...

> Sorry if it is of no help either,
No problem. I'm getting used to it... ;-)

> Gennady.

gegroet,
Erik V.

Lloyd Zusman

1/18/2005 1:08:00 AM

0

"Erik Veenstra" <google@erikveen.dds.nl> writes:

>> > > > How can I let Ruby ignore RUBYOPT?
>> > > >
>> > > > Both -T1 and unsetting the environment variable aren't
>> > > > possible in my situation. I don't want the rest of the
>> > > > script to run in safe mode 1 and I don't have control
>> > > > of the environment...
>> > >
>> > > I haven't followed this thread, but since the internal
>> > > ENV only affects the current process and its children,
>> > > can you wrap your program in a script that unsets RUBYOPT
>> > > and then just fork/popen the real program?
>> >
>> > No, I can't. I start ruby.exe from a little FreePascal
>> > program, which does have getenv(), but no such thing as
>> > setenv().
>>
>> Have you checked for putenv()?
>
> Briliant idea! And yes, I've checked it. And no, it doesn't
> exist...

How about using something like this in your FreePascal program:

Exec(GetEnv('COMSPEC'), '/C "set RUPYOPT=& \path\to\ruby ..."')

This uses the system command processor to execute the following two
commands (the ampersand is a command separator):

set RUBYOPT=
\path\to\ruby ...

Make sure that the equal sign after "RUBYOPT" touches the ampersand, or
else there will be a "RUBYOPT" variable in your environment that
contains a single blank. As long as the equal sign touches the
ampersand, this completely removes RUBYOPT from your environment before
invoking \path\to\ruby.

--
Lloyd Zusman
ljz@asfast.com
God bless you.



Erik Veenstra

1/18/2005 1:30:00 AM

0

> How about using something like this in your FreePascal
> program:
>
> Exec(GetEnv('COMSPEC'), '/C "set RUPYOPT=& \path\to\ruby
> ..."')
>
> This uses the system command processor to execute the
> following two commands (the ampersand is a command
> separator):

On Windows 2000:

S:\>echo 1&echo 2
1
2

On Windows 98:

S:\>echo 1&echo 2
1&echo 2

That's not gonna work...

Thanks.

gegroet,
Erik V.

Lloyd Zusman

1/18/2005 2:47:00 AM

0

"Erik Veenstra" <pan@erikveen.dds.nl> writes:

>> How about using something like this in your FreePascal
>> program:
>>
>> Exec(GetEnv('COMSPEC'), '/C "set RUPYOPT=& \path\to\ruby
>> ..."')
>>
>> This uses the system command processor to execute the
>> following two commands (the ampersand is a command
>> separator):
>
> On Windows 2000:
>
> S:\>echo 1&echo 2
> 1
> 2
>
> On Windows 98:
>
> S:\>echo 1&echo 2
> 1&echo 2
>
> That's not gonna work...
>
> Thanks.

Oh well ... [sigh]

You seem to have some rather restrictive constraints:

- This must run under FreePascal, a language which doesn't
seem to offer anything like setenv.

- This must not make use of any auxiliary .BAT files.

- This has to run under Windows 98.

Combining these limitations with the fact that ruby doesn't seem to
offer a way to ignore RUBYOPT, then it appears like you're stuck with
having to use some sort of ugly work-around, such as the nested ruby
solutions mentioned earlier.

In other words, it seems to be that your only option is to choose which
form of ugliness offends you the least.

Here's yet another piece of ugliness to consider:

I know you said no .BAT files, but would it fit within your restrictive
constraints to just create a temporary .BAT file, execute it, and then
delete it right away? Or is that also beyond the pale in your execution
environment?

If this is feasible, you can put this logic into your FreePascal
program:

Open a file named "xxxxxxxx.bat" for writing, where "xxxxxxxx"
is a unique string of valid filename characters.

Write the following into that file:

@echo off
set RUBYOPT=
\path\to\ruby program args ...

Close the file

Invoke this command:

Exec(GetEnv('COMSPEC'), '/C call xxxxxxxx.bat')

Delete "xxxxxxxx.bat"

This is no uglier than those nested ruby suggestions.


--
Lloyd Zusman
ljz@asfast.com
God bless you.



Curt Hibbs

1/18/2005 3:24:00 AM

0

Lloyd Zusman wrote:
>
> Oh well ... [sigh]
>
> You seem to have some rather restrictive constraints:
>
> - This must run under FreePascal, a language which doesn't
> seem to offer anything like setenv.
>
> - This must not make use of any auxiliary .BAT files.
>
> - This has to run under Windows 98.
>
> Combining these limitations with the fact that ruby doesn't seem to
> offer a way to ignore RUBYOPT, then it appears like you're stuck with
> having to use some sort of ugly work-around, such as the nested ruby
> solutions mentioned earlier.

You could also hack the ruby interpreter, itself, and build yourself a
custom version of ruby that can (or does) ignore RUBYOPT.

Curt