I have a relatively simple script that was working. Nothing in the script changed and I'm using ruby 1.8.6.
require 'net/ftp'
ftp = Net:: FTP.new(ip)
ftp.login(user=name,passwd=pass)
ftp.chdir(pathHere)
ftp.gettextfile('onhandapt.txt', File.basename('onhandapt.txt'))
ftp.close
I know from running through the steps in irb that I can login successfully, and even issue a ftp.list command to get the current directory, but ftp.chdir is where the scripts fails. In irb, the ftp.chdir command yields 'nil'. Double checked the path on the server.
The script produces this error:
c:/ruby/lib/ruby/1.8/net/ftp.rb:211:in readline': Invalid argument (Errno::EINVAL)
from c:/ruby/lib/ruby/1.8/net/ftp.rb:211:ingetline'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:221:in getmultiline'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:235:ingetresp'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:251:in voidresp'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:274:invoidcmd'
from c:/ruby/lib/ruby/1.8/monitor.rb:242:in synchronize'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:290:insendport'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:298:in makeport'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:329:intransfercmd'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:421:in retrlines'
from c:/ruby/lib/ruby/1.8/monitor.rb:242:insynchronize'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:419:in retrlines'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:518:ingettextfile'
Ideas welcome.
make sure pathHere contains a valid pathname and not set to nil
Figured it out. We had some office network changes. I now need to use passive mode, which can be set with this command: ftp.passive=true
Related
I have a local app (NotePlan) installed on macOS, and it publishes an x-callback-url scheme. I'm simply trying to call it from a ruby script, but can't find help on this. (Plenty of help available for HTTP calls, but this is to a local app.)
require 'open-uri'
title = "note title"
uri = "noteplan://x-callback-url/openNote?noteTitle=#{title}"
uriEncoded = URI.escape(uri)
response = open(uriEncoded).read
It returns this error:
No such file or directory # rb_sysopen - noteplan://x-callback-url/openNote?noteTitle=note%20title (Errno::ENOENT)
From the command line calling open "noteplan://x-callback-url/openNote?noteTitle=note%20title" does the expected thing, so the basic mechanism appears to work.
Well, I've found a way, though I regard it a hack, not a good answer.
response = %x[open "#{uri}"]
i.e. call the open command in a new shell.
I still hope someone can provide a better answer.
Im trying to execute shell commands using ruby, but i cant change directory to PATH with blank spaces.
variable = %x[cd #{ENV["HOME"]}/Virtual\\ VMs/]
This is not working.
Thank you
To be absolutely safe:
path = File.join [ENV["HOME"], 'Virtual VMs']
variable = %x[cd '#{path}']
Please note, that cd has empty output, so to make sure it works one probably wants to do smth like:
path = File.join [ENV["HOME"], 'Virtual VMs']
variable = %x[cd '#{path}' && ls -la]
#⇒ "total 32\ndrwxr-xr-x ....."
What is ist supposed to do? You try to chdir into a directory, but then don't do anything in it. Your variable will be empty in any case. Aside from the fact that it is pointless to do, you can not reliably execute a cd by itself in this way, because it is not an executable file. You can see this if you just execute %x[cd]. You will get an Errno::ENOENT exception.
Maybe you should first describe in a broader context, what you want to achieve with your code. Where would you like to change the working directory? Within the Ruby process - in which case you have to use Dir.chdir - or in the child process - in which case you have to execute some command after the cd.
Running the command ocra script.rb --no-autoload --no-enc --add-all-core gives me the error initialize: can't convert nil into String (TypeError) for the following line:
doc = Nokogiri::XML(File.open(ARGV[0]))
Whats going on here? I want to build the executable to be able to take any argument and use that file as the xml configuration.
It seems a long time but the accept solution doesn't work for me.
The working solution is adding -- then any fake data to your argument to make the execution flow to be just as normal
example for:
so you need to do
ocra yourscript.rb -- ANYDATAHERE
Just add this above that line:
exit if defined? Ocra
# skip anything below this line when we're building the exe
Unless there's a require or otherwise loaded dependency below that line you should be fine.
I'm trying to reference a file to write to it using RubyMine and I'm having trouble figuring it out. When using the full path, the code errors out while running it with RubyMine.
When I use the same code and run it in terminal, the code works fine using the command:
ruby studio_game players.csv
How can I get the file to be recognized without having to designate the full path in RubyMine?
Erring Code:
require_relative 'player'
require_relative 'game'
player1 = Player.new("moe")
player2 = Player.new("larry", 60)
player3 = Player.new("curly", 125)
knuckleheads = Game.new("Knuckleheads")
knuckleheads.load_players(ARGV.shift || 'players.csv')
Error message:
/Users/MNickey/.rvm/rubies/ruby-1.9.3-p448/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) "/Users/MNickey/RubymineProjects/PragmaticStudio/Stooges Game/studio_game"
/Users/MNickey/RubymineProjects/PragmaticStudio/Stooges Game/game.rb:83:in `readlines': No such file or directory - players.csv (Errno::ENOENT)
from /Users/MNickey/RubymineProjects/PragmaticStudio/Stooges Game/game.rb:83:in `load_players'
from /Users/MNickey/RubymineProjects/PragmaticStudio/Stooges Game/studio_game:9:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
knuckleheads.load_players(ARGV.shift || 'players.csv') is almost certainly what is causing the problem. Unless you have configured the launcher for the script with a command line argument, ARGV will be empty and you will be getting plain-old 'players.csv' as the result.
I'm pretty certain you are running the script with an argument when you run it in the command line.
To set a command line parameter in RubyMine, go to Run / Edit Configurations, find the launch configuration for your script, and add the path to your csv file to the Script Arguments input box.
Hi I have been testing some very basic things in ruby and discover the following.
If i put in a file called xxxx.rb in this path "C:\Documents and Settings\Desktop\xxxx.rb"
puts __FILE__
and invoke this ruby file in a command line WITHOUT preceding ruby the output is the following
C:/Documents and Settings/Desktop/xxxx.rb
but if i invoke the xxxx.rb file with ruby (ruby xxxx.rb) in the command like the output is the following:
xxxx.rb
Why is that difference?? Thanks
PD: I'M ON WINDOWS XP SP3
RUBY VERSION: 1.8.6
What you want is to expand the path properly:
# Affected by the current working directory, etc.
puts __FILE__
# Always an absolute path
puts File.expand_path(__FILE__, Dir.getwd)
This takes your current working directory into account.
I'm guessing that when you just double click on the file, the absolute path gets passed. You should achieve the same effect by calling it like:
ruby C:/Documents and Settings/Desktop/xxxx.rb