Ruby与系统输入

Ruby与系统输入,ruby,Ruby,我有一个与系统命令一起运行的命令。 我可以记录传递给shell的内容吗 另外,我遇到了qoutes=)的问题。在将字符串发送到系统命令之前,只需打印字符串即可 command = "whoami" # store the command as string puts command # print it before you execute it system(command) # execute it in the shell 你提到了“报价的问题”。我想你是说双引号

我有一个与系统命令一起运行的命令。 我可以记录传递给shell的内容吗


另外,我遇到了qoutes=)的问题。

在将字符串发送到系统命令之前,只需打印字符串即可

command = "whoami"  # store the command as string
puts command        # print it before you execute it
system(command)     # execute it in the shell
你提到了“报价的问题”。我想你是说双引号吧?将Vapire的解决方案修改为:

command = %Q{echo "double quoted string"}  # store the command as string
puts command                               # print it before you execute it
system(command)                            # execute it in the shell

你说的“通过了什么”是什么意思?系统命令返回的结果?将在Shell中调用的确切字符串是否要捕获命令的输出?