如何在默认应用程序中打开文件.红宝石 [英] How to open file in default application. Ruby
本文介绍了如何在默认应用程序中打开文件.红宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Ruby脚本在其默认应用程序中打开文件?
How to open file in its default application using Ruby scripts?
让我们说,我有一个文件名为.txt .doc .rb的文件夹,我想分别用记事本,Word和RubyMine打开它们.我假设所有文件都有其默认应用程序可以打开.
Let us say, I have folder with files .txt .doc .rb and I would like open them with Notepad, Word, and RubyMine respectively. I assume that all files have their default applications to open.
推荐答案
这应该有效(未经测试,因为我现在不在Windows计算机上):
This should work (untested, as I'm not on a Windows machine now):
file_to_open = "c:\path\to\file.txt"
system %{cmd /c "start #{file_to_open}"}
作为参考,这也可以在OS X上完成:
For reference, this can also be done on OS X:
file_to_open = "/path/to/file.txt"
system %{open "#{file_to_open}"}
这篇关于如何在默认应用程序中打开文件.红宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文