Dale, Something odd here - see below . . On Tue, 2006-06-20 at 23:54 +0900, Dale Martenson wrote: > Philip Rhoades wrote: > > Dale, Darren, > > > > > > On Tue, 2006-06-20 at 05:04 +0900, Dale Martenson wrote: > >> > > >> $stdin = IO.popen("cat parsefile") > >> > >> You can now start debugging. All input will be read from the result of > >> the IO.popen call. > >> > >> --Dale Martenson > > > > > > Using both this method and: > > > > ruby -r debug t1.rb < parsefile (which I had already tried) > > > > do strange things - eg: > > > > [root@prix bin]# ruby -r debug t1.rb > > Debug.rb > > Emacs support available. > > > > t1.rb:6:require 'ftools' > > (rdb:1) $stdin = IO.popen("cat t") > > #<IO:0xb7f16708> > > (rdb:1) Received: from localhost (HELO localhost.localdomain) > > (127.0.0.1) by prix.pricom.com.au with SMTP; 20 Jun 2006 08:11:43 -0000 > > t1.rb:6:compile error > > t1.rb:6: syntax error, unexpected ':', expecting $end > > . > > . > > similar repeated errors for the rest of the parsefile ('t") > > > > > > The top of t1.rb looks like: > > > > #!/usr/bin/ruby > > # qmail-pfilter.rb > > # v1.1 > > # 2006-03-14 > > > > require 'ftools' (line 6) > > > > The first line of the mail item - text file "t" (parsefile) is read in > > and then I get the compile/syntax errors - these continue for the whole > > of the rest of the text file but I need to be able to step through the > > program one line at a time from the parsefile . . > > > > What is going on? > > > > I don't know. I am not sure what your program is doing. Is there anyway > you could share the source. Or could you reduce the program down to a > simple case that still causes the problem. > > Here is a very simple program that attempts to show a couple of things. > > 1. I required 'ftools' since that seems to be where you are getting into > trouble. It is not needed by the program. Then stepped in the debugger > to see what happens when the "require 'ftools'" line is processed. You > should do the same. > > 2. The program takes the piped input and burps it back out again with a > prefix. The input is just the program source itself. > > ------ d.rb ------ > > #!/usr/bin/env ruby > > require 'ftools' > > $stdin.each_line do |line| > puts "BUBBA: "+line > end > puts "BUBBA END." > > ------ EOF ------ > > Here is my output when I stepped through the program in the debugger. > > ------ output ------ > > # ruby -r debug d.rb > Debug.rb > Emacs support available. > > d.rb:3:require 'ftools' > (rdb:1) $stdin = IO.popen( "cat d.rb" ) > #<IO:0x401f5f40> > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:1:class << File > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:3: BUFSIZE = 8 * 1024 > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:5: def catname from, to > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:15: def syscopy from, to > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:41: def copy from, to, verbose = false > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:46: alias cp copy > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:50: def move from, to, verbose = false > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:75: alias mv move > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:81: def compare from, to, verbose = false > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:112: alias cmp compare > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:116: def safe_unlink(*files) > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:127: alias rm_f safe_unlink > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:129: def makedirs(*dirs) > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:148: alias mkpath makedirs > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:150: alias o_chmod chmod > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:152: vsave, $VERBOSE = $VERBOSE, false > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:153: def chmod(mode, *files) > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:158: $VERBOSE = vsave > (rdb:1) s > /usr/lib/ruby/1.8/ftools.rb:160: def install(from, to, mode = nil, > verbose = false) > (rdb:1) s > d.rb:5:$stdin.each_line do |line| > (rdb:1) s > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: #!/usr/bin/env ruby > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: require 'ftools' > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: $stdin.each_line do |line| > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: puts "BUBBA: "+line > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: end > d.rb:6: puts "BUBBA: "+line > (rdb:1) s > BUBBA: puts "BUBBA END." > d.rb:8:puts "BUBBA END." > (rdb:1) s > BUBBA END. > # > > ------ EOF ------ > > You should attempt to step through your program to see what happens. You > may want to turn on trace. [root@prix bin]# ruby -r debug debugtst.rb Debug.rb Emacs support available. debugtst.rb:3:require 'ftools' (rdb:1) $stdin = IO.popen( "cat debugtst.rb" ) #<IO:0xb7f676c8> (rdb:1) #!/usr/bin/env ruby nil (rdb:1) #!/usr/bin/env ruby nil (rdb:1) require 'ftools' true (rdb:1) require 'ftools' false (rdb:1) $stdin.each_line do |line| debugtst.rb:3:compile error debugtst.rb:3: syntax error, unexpected $end $stdin.each_line do |line| ^ (rdb:1) puts "BUBBA: "+line debugtst.rb:3:undefined local variable or method `line' for main:Object (rdb:1) end debugtst.rb:3:compile error debugtst.rb:3: syntax error, unexpected kEND (rdb:1) puts "BUBBA END." BUBBA END. nil (rdb:1) puts "BUBBA END." BUBBA END. nil (rdb:1) puts "BUBBA END." BUBBA END. nil (rdb:1) puts "BUBBA END." BUBBA END. nil (rdb:1) I don't get the chance to step . . it looks like something peculiar to my system (FC5 + latest Ruby) . . any idea what? Thanks, Phil. -- Philip Rhoades Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275) GPO Box 3411 Sydney NSW 2001 Australia Mobile: +61:(0)411-185-652 Fax: +61:(0)2-8221-9599 E-mail: phil / pricom.com.au