[英]Executing cmd command with variables in Ruby fails
I'm writting Windows account report in Ruby. 我正在用Ruby写Windows帐户报告。 I have an array with usernames
我有一个包含用户名的数组
users_local = [user1, user2, user3]
For every single user I want to execute a cmd command to get more information about every user 我想为每个用户执行一个cmd命令以获取有关每个用户的更多信息
system "net user '#{users_local[0]}'"
and now I get 现在我明白了
The user name could not be found.
More help is available by typing NET HELPMSG 2221.
When I execute directly system 'user net user1'
the command is executing correctly. 当我直接执行
system 'user net user1'
,命令正确执行。 Any ideas why executing command with variable fails? 有什么想法为什么用变量执行命令失败?
摆脱单引号应该做到这一点:
system "net user #{users_local[0]}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.