snacktime wrote:
> I'm trying to figure out why a particular system command is returning
> false on windows.
> 
> This works fine and returns true:
> 
> res = system('dir')
> 
> This returns false with $? being nil:
> 
> res = system('rake')
> 
> if I just run rake at the command line it works fine.   I'm sure this
> is something simple, but windows is not a development environment I am
> used to.
Try cmd=ExecCmd.new("rake");puts cmd.success?;puts cmd.output  using the 
class at the end of this message (Ara's solution for grabbing the output 
  of stderr and stdout on windows with a broken popen3 was better - 
giving you separate stderr und stdout - but this one has benchmarking 
too :) ).

I get

false
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, 
Rakefile.rb)
d:/dev/ruby/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1373:in 
`load_rakefile'

on a directory without a rakefile, which is correct :).

system("rake") for the same directory gives a $? of 256.

--------
class ExecCmd
	attr_reader :output,:cmd,:exec_time
	#When a block is given, the command runs before yielding
	def initialize cmd
	@cmd=cmd
	@cmd_run=cmd+" 2>&1" unless cmd=~/2>&1/
	if block_given?
		run
		yield self
	end
	end
	#Runs the command
	def run
		t1=Time.now
		IO.popen(@cmd_run){|f|
		@output=f.read
		@process=Process.waitpid2(f.pid)[1]
		}
		@exec_time=Time.now-t1
	end
	#Returns false if the command hasn't been executed yet
	def run?
		return false unless @process
		return true
	end
	#Returns the exit code for the command. Runs the command if it hasn't 
run yet.
	def exitcode
		run unless @process
		@process.exitstatus
	end
	#Returns true if the command was succesfull.
	#
	#Will return false if the command hasn't been executed
	def success?
		return @process.success? if @process
		return false
	end
end

-- 
http://www.braveworld.net/riva

____________________________________________________________________
http://www.freemail.gr - δωρεάν υπηρεσία ηλεκτρονικού ταχυδρομείου.
http://www.freemail.gr - free email service for the Greek-speaking.