Paulo Carvalho
2012-Jun-12 13:49 UTC
Opening a file having white spaces on is name with the default program
Hello, In my rails application, I have a file which name is: "d:/Copy of t.txt". I want to open it with the default program. This file is a TXT file but it can be another kind of file (png, pdf, etc) and can have, or not, white spaces on his path/name. I''ve tried several ways to do it but, until now, I was not able to accomplish by goal. I have tried: f1 = "d:/Copy of t.txt" #system %{cmd /c "start #{f1}"} #cmd = ''cmd /c "start '' + f1 + ''"'' #cmd = ''cmd /c """start '' + f1 + ''"""'' #cmd = "cmd /c ""start ''" + f1 + "''""" cmd = "cmd /c ""start ''" + f1 + "''""" system (cmd) But no one of these solutions has worked. Anyone can help me? Thank you Best regards -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Oscar Del Ben
2012-Jun-12 14:25 UTC
Re: Opening a file having white spaces on is name with the default program
I don''t use windows, but you could try escaping the space "foo\ bar" -- Oscar Del Ben Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Tuesday, June 12, 2012 at 6:49 AM, Paulo Carvalho wrote:> Hello, > > In my rails application, I have a file which name is: "d:/Copy of > t.txt". > > I want to open it with the default program. > > This file is a TXT file but it can be another kind of file (png, pdf, > etc) and can have, or not, white spaces on his path/name. > > I''ve tried several ways to do it but, until now, I was not able to > accomplish by goal. > > I have tried: > > f1 = "d:/Copy of t.txt" > > #system %{cmd /c "start #{f1}"} > #cmd = ''cmd /c "start '' + f1 + ''"'' > #cmd = ''cmd /c """start '' + f1 + ''"""'' > #cmd = "cmd /c ""start ''" + f1 + "''""" > cmd = "cmd /c ""start ''" + f1 + "''""" > > system (cmd) > > But no one of these solutions has worked. > > Anyone can help me? > > Thank you > > Best regards > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Paulo Carvalho
2012-Jun-12 14:32 UTC
Re: Opening a file having white spaces on is name with the default program
Hello, Thanks for your answer. However, still not working... f1 = "d:/Copy of t.txt" f1 = f1.gsub(" ", "\\ ") #system %{cmd /c "start #{f1}"} #cmd = ''cmd /c "start '' + f1 + ''"'' #cmd = ''cmd /c """start '' + f1 + ''"""'' #cmd = "cmd /c ""start ''" + f1 + "''""" cmd = "cmd /c ""start ''" + f1 + "''""" system (cmd) Oscar Del Ben wrote in post #1064217:> I don''t use windows, but you could try escaping the space "foo\ bar" > > -- > Oscar Del Ben > Sent with Sparrow (http://www.sparrowmailapp.com/?sig)-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Jun-12 14:49 UTC
Re: Opening a file having white spaces on is name with the default program
On 12 June 2012 14:49, Paulo Carvalho <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello, > > In my rails application, I have a file which name is: "d:/Copy of > t.txt". > > I want to open it with the default program. > > This file is a TXT file but it can be another kind of file (png, pdf, > etc) and can have, or not, white spaces on his path/name. > > I''ve tried several ways to do it but, until now, I was not able to > accomplish by goal. > > I have tried: > > f1 = "d:/Copy of t.txt" > > #system %{cmd /c "start #{f1}"} > #cmd = ''cmd /c "start '' + f1 + ''"'' > #cmd = ''cmd /c """start '' + f1 + ''"""'' > #cmd = "cmd /c ""start ''" + f1 + "''""" > cmd = "cmd /c ""start ''" + f1 + "''""" > > system (cmd) > > But no one of these solutions has worked.Have you tried inserting puts cmd then copying and pasting the output into the terminal to see if that works? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Victor Goff
2012-Jun-13 02:01 UTC
Re: Opening a file having white spaces on is name with the default program
For a Microsoft DOS file name it is wrong. It should be "d:\Copy of t.txt". Your problem could simply be the escaping of the backslash. As you have shown it in rails, you would be escaping the C character. On Tue, Jun 12, 2012 at 9:49 AM, Paulo Carvalho <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Hello, > > In my rails application, I have a file which name is: "d:/Copy of > t.txt". > > I want to open it with the default program. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Paulo Carvalho
2012-Jun-13 08:05 UTC
Re: Opening a file having white spaces on is name with the default program
Hello, Thanks for your answer. I have made a put of the command f1 = "d:/sat - Copy.png" f1 = f1.gsub(" ", "\ ") cmd = ''cmd /c "start '' + f1 + ''"'' puts "CMD: " + cmd system (cmd) ....and the result is the following one: cmd /c "start d:/sat - Copy.png" In attachment, I''ve putted a picture with the error. Thanks Regards Colin Law wrote in post #1064223:> On 12 June 2012 14:49, Paulo Carvalho <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> I''ve tried several ways to do it but, until now, I was not able to >> cmd = "cmd /c ""start ''" + f1 + "''""" >> >> system (cmd) >> >> But no one of these solutions has worked. > > Have you tried inserting > puts cmd > then copying and pasting the output into the terminal to see if that > works? > > ColinAttachments: http://www.ruby-forum.com/attachment/7487/err.png -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Jun-14 08:04 UTC
Re: Re: Opening a file having white spaces on is name with the default program
On 13 June 2012 09:05, Paulo Carvalho <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello,Please don''t top post, it makes it difficult to follow the thread. Insert your reply inline in previous post. Thanks> > Thanks for your answer. > > I have made a put of the command > > f1 = "d:/sat - Copy.png" > f1 = f1.gsub(" ", "\ ") > cmd = ''cmd /c "start '' + f1 + ''"'' > puts "CMD: " + cmd > system (cmd) > > ....and the result is the following one: > > cmd /c "start d:/sat - Copy.png"Exactly what command are you trying to execute? Colin> > In attachment, I''ve putted a picture with the error. > > Thanks > > Regards > > > > Colin Law wrote in post #1064223: >> On 12 June 2012 14:49, Paulo Carvalho <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> I''ve tried several ways to do it but, until now, I was not able to >>> cmd = "cmd /c ""start ''" + f1 + "''""" >>> >>> system (cmd) >>> >>> But no one of these solutions has worked. >> >> Have you tried inserting >> puts cmd >> then copying and pasting the output into the terminal to see if that >> works? >> >> Colin > > Attachments: > http://www.ruby-forum.com/attachment/7487/err.png > > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.