【问题标题】:Lua and the white spaces in an OSLua 和操作系统中的空白
【发布时间】:2011-04-12 19:09:29
【问题描述】:

reading this post之后,我使用[[ ]]将命令放入系统。问题如下:结构相同:

local Program = [["c:\Archivos de programa\Automated QA\TestComplete 8\Bin\TestComplete.exe" ]];
local testcase = [["C:\svn_test\trunk\Automation\XMM\XMM.pjs" ]];
local options = [[/r /exit /p:XMMGeneralTest /t:"Script|main|Main" ]];

local cmd = Program..testcase..options;
print(cmd);
os.execute(cmd);

local tcLog = [[ C:\svn_test\trunk\Automation\XTYLE\XTyleGeneralTest\Log\11_04_2011_12_40_06_264\*]];
local zippedFile = "11_04_2011_12_40_06_264.7z ";
local sevenZip = [["c:\Archivos de Programa\7-Zip\7z.exe" a -t7z ]];

local cmd = sevenZip..zippedFile..tcLog;
print(cmd);
os.execute(cmd);

相同的代码产生不同的结果。第一个没有运行:

"c:\Archivos" not recognized as internal command or external,
program...

第二个运行完美。

我该如何解决这个问题?

【问题讨论】:

  • 我不知道这是否是原因,但在第一种情况下,树字符串之间不需要空格吗?
  • 是的,我在编辑这篇文章时错过了这个空格,但这不是这个错误的原因:(
  • 我这里没有窗户,所以我无法真正测试这个,抱歉。

标签: lua whitespace


【解决方案1】:

我也没有 Windows 系统可以测试,所以这只是一个猜测:

尝试替换这个:

local Program = [["c:\Archivos de programa\Automated QA\TestComplete 8\Bin\TestComplete.exe" ]];

用这个:

local Program = [[c:\\Archivos\ de\ programa\\Automated\ QA\\TestComplete\ 8\\Bin\\TestComplete.exe ]];

我担心它不会起作用,因为[[]] 会阻止对转义的解释,但是随着它从一个变量到另一个变量然后到os.execute,这可能会发生变化。另一种选择是使用这些文件的 windows 版本,不带空格,例如:

local Program = [[c:\Archiv~1\Automa~1\TestCo~1\Bin\TestComplete.exe ]];

【讨论】:

  • 本地程序 = [[c:\Archiv~1\Automa~1\TestCo~1\Bin\TestComplete.exe ]];这很好用,在我找到更好的解决方案之前它会起作用:)
  • 请注意,这不是 Lua 问题。尝试从 cmd shell 运行相同的命令。你必须逃避空格。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-27
  • 2010-09-22
  • 2017-04-24
  • 2012-02-20
  • 2014-03-03
  • 1970-01-01
  • 2012-02-05
相关资源
最近更新 更多