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:in
`fu_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:in `mv'
        from
e:/live/scripts/ruby/asura-non/rcscr/RCSCR_PDF_single.rb:26:in `<main>'

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

Thanks,
Peter

···

--
Posted via http://www.ruby-forum.com/.

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

···

--
Posted via http://www.ruby-forum.com/.

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

···

--
Posted via http://www.ruby-forum.com/\.

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?

···

On Wed, May 8, 2013 at 7:14 AM, Peter Bailey <lists@ruby-forum.com> wrote:

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

--
Posted via http://www.ruby-forum.com/\.

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

···

--
Posted via http://www.ruby-forum.com/\.

can you post some of the script?

···

On Wed, May 8, 2013 at 6:43 AM, Peter Bailey <lists@ruby-forum.com> wrote:

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

--
Posted via http://www.ruby-forum.com/\.

Daniel Stephens 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 prodadmin@bna.com
-fromfriendly \"MAKO Mail Server\" -from pbailey@bna.com -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 prodadmin@bna.com
-fromfriendly \"MAKO Mail Server\" -from pbailey@bna.com -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 prodadmin@bna.com
-fromfriendly \"MAKO Mail Server\" -from pbailey@bna.com -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)

···

--
Posted via http://www.ruby-forum.com/\.

Daniel Stephens wrote in post #1108224:

can you post some of the script?

Yes! that would be easy to help him out.

···

--
Posted via http://www.ruby-forum.com/\.

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

···

On Wed, May 8, 2013 at 7:34 AM, Love U Ruby <lists@ruby-forum.com> wrote:

Daniel Stephens wrote in post #1108224:
> can you post some of the script?

Yes! that would be easy to help him out.

--
Posted via http://www.ruby-forum.com/\.

Daniel Stephens 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 ==."

···

--
Posted via http://www.ruby-forum.com/\.

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.

···

On Wed, May 8, 2013 at 8:17 AM, Peter Bailey <lists@ruby-forum.com> wrote:

Daniel Stephens 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 ==."

--
Posted via http://www.ruby-forum.com/\.

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

···

--
Posted via http://www.ruby-forum.com/\.

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

right before this line:
   pdffile = ARGV[0]

and see what happens :slight_smile:

···

On Wed, May 8, 2013 at 6:54 AM, Peter Bailey <lists@ruby-forum.com> 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.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

Hassan Schroeder wrote in post #1108253:

···

On Wed, May 8, 2013 at 6:54 AM, Peter Bailey <lists@ruby-forum.com> > 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 `<main>':
no file specified (RuntimeError)

--
Posted via http://www.ruby-forum.com/\.

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 Wed, May 8, 2013 at 8:22 AM, Peter Bailey <lists@ruby-forum.com> 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 `<main>':
no file specified (RuntimeError)

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

Hassan Schroeder wrote in post #1108265:

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 `<main>':
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:22 AM, Peter Bailey <lists@ruby-forum.com> > wrote:

--
Posted via http://www.ruby-forum.com/\.

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:56 AM, Peter Bailey <lists@ruby-forum.com> 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."

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

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 Schroeder < hassan.schroeder@gmail.com> wrote:

On Wed, May 8, 2013 at 8:56 AM, Peter Bailey <lists@ruby-forum.com> 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.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
Hassan Schroeder | about.me
twitter: @hassan

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 #=>

···

On May 9, 2013 2:51 AM, "Daniel Stephens" <danny.a.stephens@gmail.com> wrote:

Sent from my phone, so excuse the typos.

excellent thanks Matthew!

···

On Wed, May 8, 2013 at 4:17 PM, Matthew Kerwin <matthew@kerwin.net.au>wrote:

On May 9, 2013 2:51 AM, "Daniel Stephens" <danny.a.stephens@gmail.com> > 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.