简体   繁体   English

如何在ruby中将变量传递给系统命令?

[英]how to pass a variable to system command in ruby?

In my ruby script I need to pass a file path to system command. 在我的ruby脚本中,我需要将文件路径传递给系统命令。 For example, its like 例如,它就像

system("run.exe -l C:\\") where run.exe is my command and -l determines the local path. system(“run.exe -l C:\\”)其中run.exe是我的命令,-l确定本地路径。

Now if someone copies this to other machine drive C can be changed to drive E. 现在,如果有人将其复制到其他机器驱动器C可以更改为驱动器E.

So my doubt is how to make it as a variable or how to take the current folder path in this. 所以我的疑问是如何将其作为变量或如何获取当前文件夹路径。

Any suggestions are most welcome. 任何建议都是最受欢迎的。

mu is too short and Jan give answers, but in general, you can put ruby commands in #{...} within "..." . mu太短而Jan给出了答案,但一般来说,你可以在#{...}中将ruby命令放在"..." In this case, you can do: 在这种情况下,您可以这样做:

system("fixed_string_1#{ruby_command_1}fixed_string_2#{ruby_command_2}fixed_string_3...")

你想看看ARGFARGV

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM