`exec ': string contains null byte (ArgumentError)

cmd = "snv co #{rep} --username #{svn_user} --password #{pxs}" puts cmd # this code wotks and prints all vars values normally exec(cmd) 
 xpto.rb:69:in `exec': string contains null byte (ArgumentError) from xpto.rb:69 
 $ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux] $ gem -v 1.3.7 

What's happening? How can i solve this?

+7
source share
1 answer

Your cmd line has zero (i.e. zero) bytes in it. Using puts will not display null bytes, they will just be left out:

 1.8.7 :001 > exec "\0" ArgumentError: string contains null byte from (irb):1:in `exec' from (irb):1 1.8.7 :002 > puts "n\0n" nn => nil 

You should probably check how rep , svn_user and pxs to see if you can track the source of these null bytes, but you can use gsub! as a quick fix gsub! for delete them:

 cmd.gsub!(/\0/, '') 
+10
source

All Articles