簡體   English   中英

使用許多參數運行shell命令

[英]Run shell command with many arguments

我的命令很長,包含很多參數,並且某種程度上它無法正常工作。 以下knife命令將連接到遠程vCenter並創建一個名為node1的虛擬機。 如何包裝以下命令並在ruby中運行? 難道我做錯了什么?

var_name = 'node1'
var_folder = 'folder1'
var_datastore = 'datastore1'
var_template_file = 'template_foo'
var_template = 'foo'
var_location = 'US'

cmd = 'knife vsphere vm clone var_name --dest-folder var_folder --datastore var_datastore --template-file var_template_file --template var_template -f var_location'

system(cmd)
require 'shellwords'
cmd = "knife vsphere vm clone #{var_name.shellescape} --dest-folder #{var_folder.shellescape} --datastore #{var_datastore.shellescape} --template-file #{var_template_file.shellescape} --template #{var_template.shellescape} -f #{var_location.shellescape}"

在您的特定情況下,即使沒有shellescape ,它也可以工作,但是比遺憾更好。

您的命令中未解析變量。 嘗試對可變cmd中的所有變量使用#{var_name}等

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM