PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > How to tell if script running under rubyw vs ruby?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to tell if script running under rubyw vs ruby?

Réponse
 
LinkBack Outils de la discussion
Vieux 10/05/2008, 18h59   #1
Joe Swatosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to tell if script running under rubyw vs ruby?

I spent some time poking around in Config, but so far this is the the
only thing I've found that works:

begin
puts 'this is a test'
# here is ruby
rescue
# here is rubyw
end

And I really don't love the side effect when using ruby. Please tell
me there is a better way.

Thanks,
--
Joe Swatosh

  Réponse avec citation
Vieux 10/05/2008, 20h45   #2
Sean O'Halpin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to tell if script running under rubyw vs ruby?

On Sat, May 10, 2008 at 6:59 PM, Joe Swatosh <joe.swatosh@gmail.com> wrote:
> I spent some time poking around in Config, but so far this is the the
> only thing I've found that works:
>
> begin
> puts 'this is a test'
> # here is ruby
> rescue
> # here is rubyw
> end
>
> And I really don't love the side effect when using ruby. Please tell
> me there is a better way.
>
> Thanks,
> --
> Joe Swatosh
>
>

As you've found out, stdout doesn't work under rubyw because all three
usual streams (stdout, stdin and stderr) are closed in a Windows exe.
I don't have a Window box handy to test, but you could try checking
the value of STDOUT under rubyw - it's probably nil or something like
that or you may get .eof? == true. Only a heuristic, but should serve
to distinguish between your two use cases.

Regards,
Sean

  Réponse avec citation
Vieux 11/05/2008, 09h27   #3
Sebastian Hungerecker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to tell if script running under rubyw vs ruby?

Sean O'Halpin wrote:
> I don't have a Window box handy to test, but you could try checking
> the value of STDOUT under rubyw - it's probably nil or something like
> that or you may get .eof? == true.


Alternatively you could check for STDOUT.closed? or !STDOUT.tty?
One of those three should work at least.


HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

  Réponse avec citation
Vieux 11/05/2008, 16h06   #4
Nobuyoshi Nakada
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to tell if script running under rubyw vs ruby?

Hi,

At Sun, 11 May 2008 02:59:07 +0900,
Joe Swatosh wrote in [ruby-talk:301402]:
> I spent some time poking around in Config, but so far this is the the
> only thing I've found that works:


It depends on what you want to know. If it is

a) whether running with or without a console window, you can't
open "CONIN$" and "CONOUT$" without it.

begin
open("CONIN$") {}
# here is ruby
rescue
# here is rubyw
end

b) whether running with opened STDIN/STDOUT/STDERR, STDIN.stat
and so on fail with EBADF if it is not opened.

c) or, whether running executable is linked in GUI mode or CUI
mode, you might have to parse the exe header. (imagehlp.dll
or something may be needed.)

--
Nobu Nakada

  Réponse avec citation
Vieux 12/05/2008, 04h17   #5
Joe Swatosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to tell if script running under rubyw vs ruby?

On Sun, May 11, 2008 at 8:06 AM, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
> Hi,
>
> At Sun, 11 May 2008 02:59:07 +0900,
> Joe Swatosh wrote in [ruby-talk:301402]:
> > I spent some time poking around in Config, but so far this is the the
> > only thing I've found that works:

>
> It depends on what you want to know. If it is
>
> a) whether running with or without a console window, you can't
> open "CONIN$" and "CONOUT$" without it.
>
> begin
> open("CONIN$") {}
> # here is ruby
> rescue
> # here is rubyw
> end
>
> b) whether running with opened STDIN/STDOUT/STDERR, STDIN.stat
> and so on fail with EBADF if it is not opened.
>
> c) or, whether running executable is linked in GUI mode or CUI
> mode, you might have to parse the exe header. (imagehlp.dll
> or something may be needed.)
>
> --
> Nobu Nakada
>
>


Thanks Sean.
I should have mentioned that testing for defined?, nil?, and eof?
weren't ful.

Thanks Sebastian.
No joy on .tty? or .closed? either.

Nobu rocks again!
It is b) We are using some gems that might puts or warn when they are
loaded, so when running under rubyw we are planning to redirect them
to a log file, but we don't want to mess with anything when running
under ruby.

Thanks again everyone.

--
Joe

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h06.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10158 seconds with 13 queries