Lua和操作系统中的空白字符

阅读了这篇帖子后,我使用 [[ ]]将命令放入系统中。问题是以下结构:

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...

第二个完美运行。

我应该怎么解决这个问题?

原文链接 https://stackoverflow.com/questions/5633523

点赞
stackoverflow用户596285
stackoverflow用户596285

我也没有 windows 系统进行测试,所以这只是一个猜测:

试试将此替换为:

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 ]];
2011-04-12 11:09:29