相关疑难解决方法(0)

使用正确的参数转义从ruby在后台执行shell命令

我必须在后台运行一个命令,但我想对其参数进行适当的转义.

system("rake send_mails subject='#{params[:subject]}' 2> /dev/null 1> /dev/null &");
Run Code Online (Sandbox Code Playgroud)

如果我写,system("rake", "send_mails", params[:subject])那么我没有重定向和&标志的"位置" .如果我不这样做,我没有逃避subject参数.

我该如何解决这个问题?

ruby shell background escaping

11
推荐指数
1
解决办法
7562
查看次数

Ruby TCPSocket/HTTP请求

我刚开始使用TCPSockets.我只想尝试获取谷歌主页.这是我的代码:

require 'socket'

host = 'http://www.google.com'
port = 80

s = TCPSocket.open host, port
s.puts "GET / HTTP/1.1\r\n"
s.puts "Host: Firefox"
s.puts "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
s.puts "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
s.puts "\r\n"

while line = s.gets
  puts line.chop
end


s.close
Run Code Online (Sandbox Code Playgroud)

返回:

HTTP/1.1 302 Document has moved
Location: http://92.242.140.29/?nxdomain=http%3A%2F%2Ffirefox&AddInType=2&PlatformInfo=pbrgen
Run Code Online (Sandbox Code Playgroud)

为什么?我的目标是获取谷歌主页的内容.谢谢

ruby tcpsocket

2
推荐指数
1
解决办法
5025
查看次数

标签 统计

ruby ×2

background ×1

escaping ×1

shell ×1

tcpsocket ×1