Ruby和系统输入

时间:2011-12-30 12:39:12

标签: ruby

我有一个使用system命令运行的命令。 我可以记录传递给shell的内容吗?

P.S。我有问题qoutes =)

2 个答案:

答案 0 :(得分:1)

您可以在将字符串发送到系统命令

之前简单地打印它
command = "whoami"  # store the command as string
puts command        # print it before you execute it
system(command)     # execute it in the shell

答案 1 :(得分:1)

你提到“引号有问题”。我猜你的意思是双引号?修改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