Problem with FileUtils move command

Hello,
I’m getting this strange error for a pretty simple Ruby script that I’m
sure has run successfully in the past.

C:/Ruby200/lib/ruby/2.0.0/fileutils.rb:1631:in path': no implicit conversion of nil into String (TypeError) from C:/Ruby200/lib/ruby/2.0.0/fileutils.rb:1631:infu_each_src_dest0’
from C:/Ruby200/lib/ruby/2.0.0/fileutils.rb:1618:in
fu_each_src_dest' from C:/Ruby200/lib/ruby/2.0.0/fileutils.rb:580:inmv’
from
e:/live/scripts/ruby/asura-non/rcscr/RCSCR_PDF_single.rb:26:in `’

Can anyone explain to me what this means? Line 26 is just a simple
FileUtils move command.

Thanks,
Peter

“no implicit conversion of nil into String” means you’re probably
passing it a variable which contains nil. Inspect the variables that
you’re using on line 26.

how is the script invoked?
the fact that your ‘puts pdffile’ is not showing anything is an
indicator
that the value is nil
Could be a typo: the var that refers to the file is not actually
‘pdffile’?
or the script is not getting a file name on the command line?

Joel P. wrote in post #1108209:

“no implicit conversion of nil into String” means you’re probably
passing it a variable which contains nil. Inspect the variables that
you’re using on line 26.

Thanks. The variable is “pdffile,” which is defined 10 lines above this
line by “pdffile = ARGV[0].”

I don’t know what else to do here. I’ve put a “puts pdffile” right above
line 26, but, it doesn’t even show when I run the script.

can you post some of the script?

Chris H. wrote in post #1108213:

how is the script invoked?
the fact that your ‘puts pdffile’ is not showing anything is an
indicator
that the value is nil
Could be a typo: the var that refers to the file is not actually
‘pdffile’?
or the script is not getting a file name on the command line?

This Ruby script is activated by our scheduling software. When a file
appears in a certain directory, the scheduler kicks in this script. And,
the script acts on the files in the directory, one at a time. The file
itself is defined at the top of the Ruby script with PDFFILE = ARGV[0]

Right now I’ve got the scheduling service turned off for this job and
I’m just manually invoking the Ruby script, along with the file, in the
Windows command shell.

Daniel S. wrote in post #1108224:

can you post some of the script?

Sure. Here it is.

require ‘rubygems’
require ‘fileutils’
require ‘net/ftp’

Dir.chdir(“F:/workflows/graphics/asura-non/RCSCR/in”)

if Dir.glob(“*.pdf”).length == 0 then
exit
end

pdffile = ARGV[0]

######################## PDF Input Files #######################

#First, check to see if the PDFs are good PDFs.
pdfinfo = alchemy #{pdffile} -x 2>&1
pdfinfo.scan(/Error reading PostScript|Cannot identify file/) do |match|
if match
File.open(“//mako/logs/statusreports/RCSCR.log”, “a”) { |f| f.print
" #{pdffile} is a BAD PDF file and can’t be processed\n" }
FileUtils.mv(pdffile,
“F:/workflows/graphics/asura-non/RCSCR/badfiles”)
end
end

puts pdffile

FileUtils.mv(pdffile, “F:/workflows/graphics/asura-non/RCSCR/scratch”)

#Go to the scratch area and process the file.
Dir.chdir(“F:/workflows/graphics/asura-non/RCSCR/scratch”)

pages = pdfinfo #{pdffile}
pages.scan(/^Pages: ([0-9]{1,5})/) do ||
$pagecount = $1
end
if $pagecount != “1”
puts “\n#{pdffile} is a multi-paged PDF file.\n”
pngfile = File.basename(pdffile, “.") + “.png”
tifffile = File.basename(pdffile, ".
”) + “.tif”
alchemy #{pdffile} ---n9 -Za2 -Zc1 -Zm2 -Zd 300 300 -o
alchemy #{pdffile} -t1 -Zc1 -Zd 300 300 -U ---U
else
puts “\n#{pdffile} is a single-paged PDF file.\n”
pngfile = File.basename(pdffile, “.") + “.png”
tifffile = File.basename(pdffile, ".
”) + “.tif”
alchemy #{pdffile} -t1 -Zc1 -Zm1 -Zd 300 300 -o
info = alchemy #{tifffile} -x
info.scan(/Image size (inches): ([0-9.]{1,5})/) do |
|
info = $1
puts info
puts info.to_i

end
if info.to_i < 4
puts “#{pdffile} is less than 4 inches wide”
alchemy #{pdffile} ---n9 -Za2 -Zc1 -Zm2 -Zd 300 300 -o
else
puts “#{pdffile} is more than 4 inches wide”
alchemy #{pdffile} ---n9 -Za2 -Zc1 -Zm2 -Zd 300 300 -o
end
end

#Send to Orca
t = Time.now
begin
curl -u production:prod --data-binary @#{tifffile} -H "Content-type: application/image" -H "Expect: " http://ps2000-graphics-test.bna.com/image/loader/#{tifffile}
File.open(“E:/logs/StatusReports/RCSCR.log”, “a”) { |f| f.print “Sent
to Orca: #{tifffile} at #{t.strftime(”%m/%d/%y %H%M %p")}\n" }
rescue
File.open(“E:/logs/StatusReports/RCSCR.log”, “a”) { |f| f.print “NOT
sent to Orca: #{tifffile} at #{t.strftime(”%m/%d/%y %H%M %p")}\n" }
system(“netmailbot -logfile E:/temp/netmailbot.log -appendlog -subject
"RCSCR FILES: #{tifffile} did not go to Orca!" -to [email protected]
-fromfriendly "MAKO Mail Server" -from [email protected] -server
10.70.50.52”)
end

begin
curl -u production:prod --data-binary @#{pdffile} -H "Content-type: application/image" -H "Expect: " http://ps2000-graphics-test.bna.com/image/loader/#{pdffile}
File.open(“E:/logs/StatusReports/RCSCR.log”, “a”) { |f| f.print “Sent
to Orca: #{pdffile} at #{t.strftime(”%m/%d/%y %H%M %p")}\n" }
rescue
File.open(“E:/logs/StatusReports/RCSCR.log”, “a”) { |f| f.print “NOT
sent to Orca: #{pdffile} at #{t.strftime(”%m/%d/%y %H%M %p")}\n" }
system(“netmailbot -logfile E:/temp/netmailbot.log -appendlog -subject
"RCSCR FILES: #{pdffile} did not go to Orca!" -to [email protected]
-fromfriendly "MAKO Mail Server" -from [email protected] -server
10.70.50.52”)
end

begin
curl -u production:prod --data-binary @#{pngfile} -H "Content-type: application/image" -H "Expect: " http://ps2000-graphics-test.bna.com/image/loader/#{pngfile}
File.open(“E:/logs/StatusReports/RCSCR.log”, “a”) { |f| f.print “Sent
to Orca: #{pngfile} at #{t.strftime(”%m/%d/%y %H%M %p")}\n" }
rescue
File.open(“E:/logs/StatusReports/RCSCR.log”, “a”) { |f| f.print “NOT
sent to Orca: #{pngfile} at #{t.strftime(”%m/%d/%y %H%M %p")}\n" }
system(“netmailbot -logfile E:/temp/netmailbot.log -appendlog -subject
"RCSCR FILES: #{pngfile} did not go to Orca!" -to [email protected]
-fromfriendly "MAKO Mail Server" -from [email protected] -server
10.70.50.52”)
end

#Send to BWD
#PDFs.
ftp = Net::FTP.open(‘genesis.bna.com’)
ftp.login(‘pb4072’, ‘retep1’)
ftp.chdir(‘/gateway/bwd/test/normal’)
ftp.putbinaryfile(pdffile.downcase)
File.delete(pdffile)

#PNGs.
ftp = Net::FTP.open(‘genesis.bna.com’)
ftp.login(‘pb4072’, ‘retep1’)
ftp.chdir(‘/gateway/bwd/test/normal’)
ftp.putbinaryfile(pngfile.downcase)
File.delete(pngfile)

#Delete the TIFF files.
FileUtils.rm(tifffile)

What do you get if you puts “ARGV == #{ARGV[0]}” ?

Daniel S. wrote in post #1108224:

can you post some of the script?

Yes! that would be easy to help him out.

So it’s like the other guys mentioned, there appears to be no file(or
argv[0]) getting passed in. Check your calling script(invoking script)
and
make sure your arguments are correct.

Daniel S. wrote in post #1108238:

What do you get if you puts “ARGV == #{ARGV[0]}” ?

I get the same error message as before, except, right at the top I see
“ARGV ==.”

On Wed, May 8, 2013 at 6:54 AM, Peter B. [email protected]
wrote:

So it’s like the other guys mentioned, there appears to be no file(or
argv[0]) getting passed in.

OK, but, I don’t know what else to do.

Put this:
raise “no file specified” unless ARGV[0]

right before this line:
pdffile = ARGV[0]

and see what happens :slight_smile:

Hassan S. wrote in post #1108253:

On Wed, May 8, 2013 at 6:54 AM, Peter B. [email protected]
wrote:

So it’s like the other guys mentioned, there appears to be no file(or
argv[0]) getting passed in.

OK, but, I don’t know what else to do.

Put this:
raise “no file specified” unless ARGV[0]

right before this line:
pdffile = ARGV[0]

and see what happens :

Thanks. I get this:

F:\workflows\graphics\Asura-Non\RCSCR\in>e:\live\scripts\ruby\asura-non\rcscr\rcscr_pdf_single.rb
hlst205ar-15.pdf
e:/live/scripts/ruby/asura-non/rcscr/RCSCR_PDF_single.rb:11:in `':
no file specified (RuntimeError)

Daniel S. wrote in post #1108240:

So it’s like the other guys mentioned, there appears to be no file(or
argv[0]) getting passed in. Check your calling script(invoking script)
and
make sure your arguments are correct.

OK, but, I don’t know what else to do. I’ve got 60 or 70 scripts that
have the same arguments at the top that this one does. The file being
worked on is defined in the variable “pdffile.” And, that file is
defined at the top with “pdffile = ARGV[0],” which means make the
variable equal to the incoming file.

Thanks.

Hassan S. wrote in post #1108265:

On Wed, May 8, 2013 at 8:22 AM, Peter B. [email protected]
wrote:

F:\workflows\graphics\Asura-Non\RCSCR\in>e:\live\scripts\ruby\asura-non\rcscr\rcscr_pdf_single.rb

hlst205ar-15.pdf
e:/live/scripts/ruby/asura-non/rcscr/RCSCR_PDF_single.rb:11:in `':
no file specified (RuntimeError)

Is “hist205ar-15.pdf” the name you’re passing to the script? Hard
to tell with the email wrapping.

Maybe this is just broken in Windows. What ruby version are you
running? Does this following snippet return ‘foo’ ?

ruby -e “raise ‘no arg given’ unless ARGV[0]; puts ARGV[0]” foo

Yeh, that’s the name of the PDF I want the script to work on. I’m using
2.0.0p0 Ruby.

I ran your little script there, and, I got “foo.”

On Wed, May 8, 2013 at 8:56 AM, Peter B. [email protected]
wrote:

Yeh, that’s the name of the PDF I want the script to work on. I’m using
2.0.0p0 Ruby.

I ran your little script there, and, I got “foo.”

Well, I can’t imagine how you could be passing in an argument and
yet ARGV is empty. I certainly can’t find any way to reproduce it on
OS X.

Do you have another Windows box to try it on? Alternately move
that raise statement to be the first program line and run the script
with -w for verbose output, though I doubt that’ll tell us anything
different.

On Wed, May 8, 2013 at 8:22 AM, Peter B. [email protected]
wrote:

F:\workflows\graphics\Asura-Non\RCSCR\in>e:\live\scripts\ruby\asura-non\rcscr\rcscr_pdf_single.rb

hlst205ar-15.pdf
e:/live/scripts/ruby/asura-non/rcscr/RCSCR_PDF_single.rb:11:in `':
no file specified (RuntimeError)

Is “hist205ar-15.pdf” the name you’re passing to the script? Hard
to tell with the email wrapping.

Maybe this is just broken in Windows. What ruby version are you
running? Does this following snippet return ‘foo’ ?

ruby -e “raise ‘no arg given’ unless ARGV[0]; puts ARGV[0]” foo

On May 9, 2013 2:51 AM, “Daniel S.” [email protected]
wrote:

Maybe it’s not in [0]?? Drop that loop at the top of your script as well
and lets see what we get.

ARGV.each do |arg|
puts “Argument: #{arg}”
end

Pro tip: When debugging vars that may be nil, use #p instead of #puts.
You
get much more useful output, e.g.:

p ARGV[0] #=> nil
p ARGV #=> []

Sent from my phone, so excuse the typos.

Maybe it’s not in [0]?? Drop that loop at the top of your script as well
and lets see what we get.

ARGV.each do |arg|
puts “Argument: #{arg}”
end

On Wed, May 8, 2013 at 11:43 AM, Hassan S. <

excellent thanks Matthew!