From: "dtown22@..." Date: 2007-10-27T03:40:07+09:00 Subject: Re: cant seem to get system() & pipe to work together Hi Mac, Thanks for taking the time to help me on this. I wasnt aware that there was a way to load executables into ruby, but the weird thing, is that if I remove the pipe (|), or separate the commands, those files are executed. Which is why I am lead to believe that my problem is the result of the pipe. But here is my program: (I slightly modified it to simplify things, but you should get the idea) def convert2MP3(path) raise ArgumentError unless File.directory?(path) ffmpeg = '"C:\\Documents and Settings\\dt\\Desktop\\my stuff\\songs\ \wma\\ffmpeg.exe"' lame = '"C:\\Documents and Settings\\dt\\Desktop\\my stuff\\songs\ \wma\\lame.exe"' Dir.entries(path).each do |child| if File.basename(child) =~ /wma$/ puts "converting to mp3" child = path + File::SEPARATOR + child child = child.gsub('/', "\\") child = child.gsub('\\\\', "\\") child = '"' + child + '"' newFile = child.sub('wma', 'mp3') #cmd = ffmpeg + " -i " + child + " -vn -f wav - | " + lame + " -V 6 - " + newFile cmd1 = "#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 - #{newFile}" #cmd2 = `#{lame} -V 6 - #{newFile}` puts cmd1 system(cmd1) if File.exists?(child) #File.delete(child) end end end end startingDir = "C:/Documents and Settings/dt/Desktop/my stuff/songs// Who The/Quadrophenia/" convert2MP3(startingDir) -d On Oct 26, 10:24 am, Michael Linfield wrote: > dtow...@gmail.com wrote: > > "C:\Documents and Settings\dt\Desktop\my stuff\songs\wma\ffmpeg.exe" - > > i "C:\Documents and Settings\dt\Desktop\my stuff\songs\Who The > > \Quadrophenia\07-0 - Who The - Love Reign O'er Me.wma" -vn -f wav - | > > "C:\Documents and Settings\dt\Desktop\my stuff\songs\wma\lame.exe" -V > > 6 - "C:\Documents and Settings\dt\Desktop\my stuff\songs\\Who The > > \Quadrophenia\07-0 - Who The - Love Reign O'er Me.mp3" > > > It works perfect from the command line, but no matter how i try it > > (with double quotes, single quotes, backticks, etc) it doesnt seem to > > want to work from ruby > > > Here is an example of the code I have > > > ffmpeg = '"C:\\Documents and Settings\\dt\\Desktop\\my stuff\\songs\ > > \wma\\ffmpeg.exe"' > > lame = '"C:\\Documents and Settings\\dt\\Desktop\\my stuff\\songs\ > > \wma\\lame.exe"' > > > newFile = child.sub('wma', 'mp3') > > #cmd = ffmpeg + " -i " + child + " -vn -f wav - | " + lame + " -V 6 - > > " + newFile > > cmd1 = "#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 - > > #{newFile}" > > puts cmd1 > > system(cmd1) > > > NOTE: child points to the same file wma file as above. > > > If i copy and paste the output of the puts command above into a > > command window, it works fine...but from ruby, it seems to ignore the > > pipe (|) command. I dont know if this is a windows issue, or if i am > > missing something obvious. Any help is greatly appreciated. > > Alright lets approach this from a different perspective. First, the > reason that lame or ffmpeg arnt working is because its loading them as > strings into ruby, instead of loading the exe's. There should be a gem > or lib in ruby that loads exe's into memory but i havnt had the time > today to fumble around the net for it. Using a gem to convert these > files would be alot better than loading exes into memory. If you were on > linux you could do all this with some bash scripting but :( we'll find > another way. > > >cmd1 = "#{ffmpeg} -i #{child} -vn -f wav - | #{lame} -V 6 - > > #{newFile}" > > the reason this isnt working is because Ruby doesnt take command line > arguements like Windows cmd.exe or command.com does. Ruby interprets > these as minus signs and negative signs. I would imagine running this > gives you some outrageous errors. If you could post your entire program > and we'll see if we cant find a gem or lib that will do this. > > - Mac > -- > Posted viahttp://www.ruby-forum.com/.