首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >os.execute变量

os.execute变量
EN

Stack Overflow用户
提问于 2013-03-26 13:54:11
回答 1查看 1.7K关注 0票数 0

我有多个Steam帐户,我想通过一个带有我指定的选项的Lua脚本启动这些帐户。除了用提供的代码启动之外,我已经把所有的事情都整理好了。我不知道如何“传递”这种格式的变量。

代码语言:javascript
复制
function Steam(n, opt1, opt2, opt3)
os.execute[["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam2 D:\Steam\steam.exe -login username password -opt1 -opt2 -opt3"]]
end

我设置了我的用户名和沙箱,这样只需要用相同的密码更改号码(fenriros2,fenriros3,Steam2,Steam3等)。

基本上,我想要这个;

代码语言:javascript
复制
Steam(3, -tf, -exit, -textmode)

待办事项;

代码语言:javascript
复制
os.execute[["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam3 D:\Steam\steam.exe -login fenriros3 password -applaunch 440 -textmode"]]

完成后,我将使用-exit关闭lua窗口。

我知道我的代码效率不是很高,但这是以后的担忧。现在我只需要让它正常工作。

任何帮助都是非常感谢的,如果我错过了一些明显的东西,我道歉,我在Lua仍然是相当新的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-26 16:10:56

第一个显而易见的问题。[]分隔一个字符串,因此您需要做的就是为该字符串创建一个变量,并根据需要替换内容。

代码语言:javascript
复制
function Steam(n, opt1, opt2, opt3)
-- Set up execute string with placeholders for the parameters.
local strExecute = [["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam{n} D:\Steam\steam.exe -login fenriros{n} password -{opt1} -{opt2} -{opt3}"]]

-- Use gsub to replace the parameters
-- You could just concat the string but I find it easier to work this way.
strExecute = strExecute:gsub('{n}',n)
strExecute = strExecute:gsub('{opt1}',opt1:gsub('%%','%%%%'))
strExecute = strExecute:gsub('{opt2}',opt2:gsub('%%','%%%%'))
strExecute = strExecute:gsub('{opt3}',opt3:gsub('%%','%%%%'))
os.execute(strExecute)
end

Steam(1,'r1','r2','r3')
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15630279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档