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

Uh oh, looks like we're going for a round of 9 holes this week:

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

Is there a more elegant (compact?) method than

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

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

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:’)

···

On Saturday 06 July 2002 10:11 pm, Bil Kleb wrote:


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

Ned Konz wrote:

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.

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 methodto_ary’ for
"connect|
www.mydomain.com|administrator|*\000":String
connect>www.mydomain.com|administrator|******
Exception NameError' at server.rbw:41 - undefined methodto_ary’ for
"connect"
:String
connect
Exception NameError' at server.rbw:41 - undefined methodto_ary’ for
"www.mydomain.com":String
www.mydomain.com
Exception NameError' at server.rbw:41 - undefined methodto_ary’ for
"administ
rator":String
administrator
Exception NameError' at server.rbw:41 - undefined methodto_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

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?

···

On Sunday 07 July 2002 10:44 am, Rich wrote:

Exception NameError' at server.rbw:41 - undefined methodto_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?


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

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

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

···

----- Original Message -----
From: “Sean Chittenden” sean@chittenden.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org; “Rich” rich@lithinos.com
Cc: “ruby-talk ML” ruby-talk@ruby-lang.org
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

Hi,

···

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

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

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

···

----- Original Message -----
From: “Ned Konz” ned@bike-nomad.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Sunday, July 07, 2002 11:59 AM
Subject: Re: Net::FTP hangs when connecting to a windows server…

On Sunday 07 July 2002 10:44 am, Rich wrote:

Exception NameError' at server.rbw:41 - undefined methodto_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

???

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

···

----- Original Message -----
From: nobu.nokada@softhome.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
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, > Ned Konz wrote:

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

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

Hi,

···

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

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

Thanks! I’ll try that!

-Rich

···

----- Original Message -----
From: nobu.nokada@softhome.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
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] > Rich wrote:

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

I ran everything with 167-0 and it doesn’t report any of the errors I had
before - but it still hangs… (linux works fine - but windows hangs)

Thanks so much for your help!

-Rich

···

----- Original Message -----
From: nobu.nokada@softhome.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
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] > Rich wrote:

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

Well - I looked at the windows 2000 server logs - didn’t say much more than
that I connected…

So I tried to find another server… my friend runs WarFTPd on a windows
box - and I had the same problems connecting.

He found the logs, and it said -

“illegal command buffer. hacking? closing connection”

So… Am I sending things too fast?? My code to connect::

Start code
$myFtp = Net::FTP::new(holder[1]) # holder[1] == server name
$myFtp.login(holder[2], holder[3]) # holder[2] == user name
listDirectory() # holder[3]
== user pass
End code

It’s fine before the ‘login’ method is called - but it never gets to the
’listDirectory method…

Any more thoughts on why I’m running into this problem with Windows servers?

-Rich