unshifting a directory onto ENV['PATH'] 
Author Message
 unshifting a directory onto ENV['PATH']

Is there a more elegant (compact?) method than

 ENV['PATH'].split(':').unshift('mystuff').join(':')

or

 ENV['PATH'] = 'mystuff:' + ENV['PATH']

for prepending something to ENV['PATH']?

Thanks,
--
Bil



Thu, 23 Dec 2004 13:27:54 GMT  
 unshifting a directory onto ENV['PATH']
Uh oh, looks like we're going for a round of 9 holes this week:

Quote:
> Is there a more elegant (compact?) method than

>  ENV['PATH'].split(':').unshift('mystuff').join(':')

> or

>  ENV['PATH'] = 'mystuff:' + ENV['PATH']

> for prepending something to ENV['PATH']?

I think your best bet is:

ENV['PATH'] = 'mystuff:' << ENV['PATH']

-sc

--
Sean Chittenden



Thu, 23 Dec 2004 13:59:07 GMT  
 unshifting a directory onto ENV['PATH']

Quote:
> Is there a more elegant (compact?) method than

>  ENV['PATH'].split(':').unshift('mystuff').join(':')

But that doesn't change ENV['PATH'], does it?

Quote:
> or

>  ENV['PATH'] = 'mystuff:' + ENV['PATH']

> for prepending something to ENV['PATH']?

Unfortunately, this doesn't work for some reason...

ENV['PATH'][0,0] = 'mystuff:'

nor this:

ENV['PATH'].sub!(/^/, 'mystuff:')

--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE



Thu, 23 Dec 2004 13:59:09 GMT  
 unshifting a directory onto ENV['PATH']

Quote:

> Unfortunately, this doesn't work for some reason...

> ENV['PATH'][0,0] = 'mystuff:'

ENV['PATH'].id == ENV['PATH'].id    # ==> false

Looks like ENV's [] method returns a copy of the string. The only way to
change ENV's data is to use []=. ENV isn't a real hash, just an
interface to the enviroment vars.



Thu, 23 Dec 2004 16:30:05 GMT  
 unshifting a directory onto ENV['PATH']
Simple FTP connection. Linux servers work just fine. Windows seems to
block/hang.
I don't have the server logs yet - maybe on Monday.
I ran the interpreter with --debug, and FTP with debug_mode=true.

Here's all relevant output::

Start output
Exception `NameError' at server.rbw:39 - undefined method `to_ary' for
"connect|
www.mydomain.com|administrator|******\000":String
connect|www.mydomain.com|administrator|******
Exception `NameError' at server.rbw:41 - undefined method `to_ary' for
"connect"
:String
connect
Exception `NameError' at server.rbw:41 - undefined method `to_ary' for
"www.mydomain.com":String
www.mydomain.com
Exception `NameError' at server.rbw:41 - undefined method `to_ary' for
"administ
rator":String
administrator
Exception `NameError' at server.rbw:41 - undefined method `to_ary' for
"*****
*\000":String
put: USER administrator
get: 331 Password required for administrator.
put: PASS **********
End output

. and then it hangs...

Start code
26 mainSocket = TCPserver.open('localhost', '4444')
27 addr = mainSocket.addr
28 addr.shift
29 print "server is on...\nIP:\t#{addr[2]}\nPort:\t#{addr[0]}\nComputer
Name:\t#{addr[1]}\n"
30
31 while(true)
32   $s = mainSocket.accept
33   peerName=$s.peeraddr
34   print(peerName, " is accepted\n")
35
36   while(true)
37     # Set the EOL character as a parameter of the 'gets' method... so
that we don't affect things globally
38     while $s.gets("\0")
39       puts $_
40       holder=$_.split("|")
41       holder.each { | item | puts item }
42
43       case holder[0]
44
45         when "abort"
End code

So... it doesn't even seem to be a problem with Net::FTP - but the NameError
is raised when I use a variable that hasn't been assigned a value - right?

Thanks for any help I can get!

-Rich



Fri, 24 Dec 2004 01:47:00 GMT  
 unshifting a directory onto ENV['PATH']

Quote:
> Exception `NameError' at server.rbw:41 - undefined method `to_ary'
> for "www.mydomain.com":String
> www.mydomain.com
> So... it doesn't even seem to be a problem with Net::FTP - but the
> NameError is raised when I use a variable that hasn't been assigned
> a value - right?

Not in your case. The NameError above just means that the String
"www.mydomain.com" doesn't understand to_ary.

Which Strings don't.

However, they understand #to_a.

You haven't re-defined "puts", have you? This is where you're having
problems in your script...

Have you tried, say, "print" or "printf" instead of puts?

--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE



Fri, 24 Dec 2004 02:02:40 GMT  
 unshifting a directory onto ENV['PATH']

Quote:
> .. and then it hangs...

> Start code
> 26 mainSocket = TCPserver.open('localhost', '4444')
> 27 addr = mainSocket.addr
> 28 addr.shift
> 29 print "server is on...\nIP:\t#{addr[2]}\nPort:\t#{addr[0]}\nComputer
> Name:\t#{addr[1]}\n"
> 30
> 31 while(true)
> 32   $s = mainSocket.accept
> 33   peerName=$s.peeraddr
> 34   print(peerName, " is accepted\n")
> 35
> 36   while(true)
> 37     # Set the EOL character as a parameter of the 'gets' method... so
> that we don't affect things globally
> 38     while $s.gets("\0")
> 39       puts $_
> 40       holder=$_.split("|")
> 41       holder.each { | item | puts item }
> 42
> 43       case holder[0]
> 44
> 45         when "abort"
> End code

> So... it doesn't even seem to be a problem with Net::FTP - but the NameError
> is raised when I use a variable that hasn't been assigned a value - right?

> Thanks for any help I can get!

Are you running into a passive vs. active FTP problem?  -sc

--
Sean Chittenden



Fri, 24 Dec 2004 04:49:40 GMT  
 unshifting a directory onto ENV['PATH']
I guess I'm not sure - how can I find out?

If it just a setting in the FTP server?

Normal FTP clients (leechFTP, cuteFTP) connect just fine...

-Rich

Quote:
----- Original Message -----



Sent: Sunday, July 07, 2002 2:45 PM
Subject: Re: Net::FTP hangs when connecting to a windows server...

> > .. and then it hangs...

> > Start code
> > 26 mainSocket = TCPserver.open('localhost', '4444')
> > 27 addr = mainSocket.addr
> > 28 addr.shift
> > 29 print "server is on...\nIP:\t#{addr[2]}\nPort:\t#{addr[0]}\nComputer
> > Name:\t#{addr[1]}\n"
> > 30
> > 31 while(true)
> > 32   $s = mainSocket.accept
> > 33   peerName=$s.peeraddr
> > 34   print(peerName, " is accepted\n")
> > 35
> > 36   while(true)
> > 37     # Set the EOL character as a parameter of the 'gets' method... so
> > that we don't affect things globally
> > 38     while $s.gets("\0")
> > 39       puts $_
> > 40       holder=$_.split("|")
> > 41       holder.each { | item | puts item }
> > 42
> > 43       case holder[0]
> > 44
> > 45         when "abort"
> > End code

> > So... it doesn't even seem to be a problem with Net::FTP - but the
NameError
> > is raised when I use a variable that hasn't been assigned a value -
right?

> > Thanks for any help I can get!

> Are you running into a passive vs. active FTP problem?  -sc

> --
> Sean Chittenden



Fri, 24 Dec 2004 05:15:47 GMT  
 unshifting a directory onto ENV['PATH']
Hi,

At Mon, 8 Jul 2002 02:59:48 +0900,

Quote:

> You haven't re-defined "puts", have you? This is where you're having
> problems in your script...

"puts" with debug option had emitted that message for a while.
Now fixed.

--
Nobu Nakada



Fri, 24 Dec 2004 05:21:00 GMT  
 unshifting a directory onto ENV['PATH']
No - this is the first ruby script that I've written, I'm not sure I'd know
how to modify the puts method.

I have modified the gets method - I'm dealing with Flash XMLSockets, and it
uses the ASCII Null as its EOL... so::

    socketConnectedToFlash.gets("\0")

is what I use instead of::

    socketConnectedToFlash.gets()

I'll replace the puts with a print and see what happens...

- or maybe I'll comment out the puts and see what happens...

-Rich

Quote:
----- Original Message -----


Sent: Sunday, July 07, 2002 11:59 AM
Subject: Re: Net::FTP hangs when connecting to a windows server...


> > Exception `NameError' at server.rbw:41 - undefined method `to_ary'
> > for "www.mydomain.com":String
> > www.mydomain.com

> > So... it doesn't even seem to be a problem with Net::FTP - but the
> > NameError is raised when I use a variable that hasn't been assigned
> > a value - right?

> Not in your case. The NameError above just means that the String
> "www.mydomain.com" doesn't understand to_ary.

> Which Strings don't.

> However, they understand #to_a.

> You haven't re-defined "puts", have you? This is where you're having
> problems in your script...

> Have you tried, say, "print" or "printf" instead of puts?

> --
> Ned Konz
> http://bike-nomad.com
> GPG key ID: BEEA7EFE



Fri, 24 Dec 2004 05:21:01 GMT  
 unshifting a directory onto ENV['PATH']
???

Now it's fixed - meaning there's a newer release I should upgrade to?

I'm using a Windows binary - 166-0...

If there is a newer release - would I be able to find a windows binary for
it?

Thanks so much for your help!

-Rich

Quote:
----- Original Message -----


Sent: Sunday, July 07, 2002 3:16 PM
Subject: Re: Net::FTP hangs when connecting to a windows server...

> Hi,

> At Mon, 8 Jul 2002 02:59:48 +0900,

> > You haven't re-defined "puts", have you? This is where you're having
> > problems in your script...

> "puts" with debug option had emitted that message for a while.
> Now fixed.

> --
> Nobu Nakada



Fri, 24 Dec 2004 05:26:14 GMT  
 unshifting a directory onto ENV['PATH']

Quote:
> I guess I'm not sure - how can I find out?

> If it just a setting in the FTP server?

> Normal FTP clients (leechFTP, cuteFTP) connect just fine...

http://www.rubydoc.org/book/c1575.htm#AEN1586

FTP is one of the worst protocols out there.  Try setting things to
active or passive and see if that helps.  If it does, then you might
want to set a timer that'll switch it between the two if the 1st
attempt fails.  Let me know if that works. -sc

--
Sean Chittenden



Fri, 24 Dec 2004 05:31:27 GMT  
 unshifting a directory onto ENV['PATH']
Hi,

At Mon, 8 Jul 2002 06:20:28 +0900, [ruby-talk:43873]

Quote:

> Now it's fixed - meaning there's a newer release I should upgrade to?

> I'm using a Windows binary - 166-0...

> If there is a newer release - would I be able to find a windows binary for
> it?

You might use PragProg version, see [ruby-talk:43432].  Or
download from http://www.dm4lab.to/~usa/ruby/index_en.html

--
Nobu Nakada



Fri, 24 Dec 2004 08:22:28 GMT  
 unshifting a directory onto ENV['PATH']
Thanks! I'll try that!

-Rich

Quote:
----- Original Message -----


Sent: Sunday, July 07, 2002 6:20 PM
Subject: Re: Net::FTP hangs when connecting to a windows server...

> Hi,

> At Mon, 8 Jul 2002 06:20:28 +0900, [ruby-talk:43873]

> > Now it's fixed - meaning there's a newer release I should upgrade to?

> > I'm using a Windows binary - 166-0...

> > If there is a newer release - would I be able to find a windows binary
for
> > it?

> You might use PragProg version, see [ruby-talk:43432].  Or
> download from http://www.dm4lab.to/~usa/ruby/index_en.html

> --
> Nobu Nakada



Fri, 24 Dec 2004 08:43:16 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. parsing ENV['PATH']

2. can't read env(DISPLAY) from regexp with $env(DISPLAY)

3. Drag'n'dropping font names onto parts

4. ENV['HOME'] on win32

5. Empty strings and 'env' array weirdness

6. DLL 'path'

7. 'require' search path

8. 'require' error (ver/path)

9. file = open(path,'wb')?????

10. execfile('bla.py'), can bla.py know its full path

11. sys.path vs os.environ['POST']

12. Tcl Tests don't support AIX's LIBPATH shlib search path

 

 
Powered by phpBB® Forum Software