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

I don’t use windows, but you could try escaping the space “foo\ bar”

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:

Have you tried inserting puts cmd then copying and pasting the output into the terminal to see if that works?

Colin

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.

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:

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