gpt4 book ai didi

ruby 使用变量执行 bash 命令

转载 作者:数据小太阳 更新时间:2023-10-29 06:49:42 26 4
gpt4 key购买 nike

我需要在 Ruby 脚本中执行 Bash 命令。根据 "6 Ways to Run Shell Commands in Ruby" by Nate Murray,大约有 6 种方法可以做到这一点以及其他一些谷歌搜索的来源。

print "enter myid: "
myID = gets
myID = myID.downcase
myID = myID.chomp
print "enter host: "
host = gets
host = host.downcase
host = host.chomp
print "winexe to host: ",host,"\n"
command = "winexe -U domain\\\\",ID," //",host," \"cmd\""
exec command

最佳答案

实际上你可以链接这些方法,puts 会为你打印一个换行符,所以这可能只是:

print "enter myid: "
myID = STDIN.gets.downcase.chomp

print "enter host: "
host = STDIN.gets.downcase.chomp

puts "winexe to host: #{host}"
command = "winexe -U dmn1\\\\#{myID} //#{host} \"cmd\""
exec command

关于ruby 使用变量执行 bash 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8159014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com