如何在默认应用程序中打开文件.红宝石

Jac*_*han 4 ruby file

如何使用Ruby脚本在其默认应用程序中打开文件?

让我们说,我有文件夹.txt .doc .rb,我想分别用Notepad,Word和RubyMine打开它们.我假设所有文件都打开了默认应用程序.

And*_*all 7

这应该工作(未经测试,因为我现在不在Windows机器上):

file_to_open = "c:\path\to\file.txt"
system %{cmd /c "start #{file_to_open}"}
Run Code Online (Sandbox Code Playgroud)

作为参考,这也可以在OS X上完成:

file_to_open = "/path/to/file.txt"
system %{open "#{file_to_open}"}
Run Code Online (Sandbox Code Playgroud)