![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
Hello, I'd need to call the OS, namely lua in it. I have the following code: ---- \write18{lua -e "require 'lfs'"} \write18{lua -e require'lfs'} \starttext A \stoptext ---- When calling directly from the command line lua -e "require 'lfs'" - there is no error. From within the Context code, I'm getting (see CmdLine.log): " ... lua.exe: (command line):1: '=' expected near 'lfs' lua.exe: (command line):1: '=' expected near '<eof>'... " What could be the problem? My OS is WinXP 32b. Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
On 14-5-2012 10:56, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
Hello,
I'd need to call the OS, namely lua in it.
I have the following code:
---- \write18{lua -e "require 'lfs'"} \write18{lua -e require'lfs'}
\starttext A \stoptext ----
When calling directly from the command line
lua -e "require 'lfs'"
- there is no error.
From within the Context code, I'm getting (see CmdLine.log):
" .... lua.exe: (command line):1: '=' expected near 'lfs' lua.exe: (command line):1: '=' expected near '<eof>'... "
What could be the problem?
My OS is WinXP 32b.
And how about \ctxlua{os.execute(lua -e "require 'lfs'")} btw, if you run texlua you get lfs for free. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
\ctxlua{os.execute(lua -e "require 'lfs'")}
... Gives: " ... fonts > latin modern fonts are not preloaded languages > language en is active ! LuaTeX error <main ctx instance>:1: attempt to call global 'e' (a nil value) stack traceback: <main ctx instance>:1: in main chunk. system > tex > error on line 4 in file C:/Lukas/ConTeXt/TestDDv/t1.mkiv: LuaTeX error ... 1 %\write18{lua -e "require 'lfs'"} 2 % 3 4 >> \ctxlua{os.execute(lua -e "require 'lfs'")} 5 %\ctxlua{os.execute([[lua -e "require 'lfs'"]])} 6 7 \starttext 8 A 9 \stoptext 10 l.4 \ctxlua{os.execute(lua -e "require 'lfs'")} ... " If I try: \ctxlua{os.execute([[lua -e "require 'lfs'"]])} I get error: " ... languages > language en is active lua: (command line):1: '=' expected near 'lfs' {c:/ConTeXt/tex/texmf-context/fonts/map/pdftex/context/mkiv-base.map} ... " (Like if "'" were gobbled...)
btw, if you run texlua you get lfs for free.
OK, this is just a sample. I need to use another file, in fact. Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
On 14-5-2012 12:23, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
\ctxlua{os.execute(lua -e "require 'lfs'")}
\ctxlua{os.execute([[lua -e "require 'lfs'"]])} ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
Hello, I slightly modified the example - my code now is: ---- \ctxlua{os.execute([[echo lua -e "print 'WWW'"]])} \starttext A \stoptext ---- So now I'm able to diagnose what exactly is passed to the command line. I'm getting: " ... languages > language en is active lua -e "print "WWW"" {c:/ConTeXt/tex/texmf-context/fonts/map/pdftex/context/mkiv-base.map} ... " So it can be seen that [surprisingly] character ' was substituted for " - and IMHO this causes the problem. Could anyone explain why this substitution is performed and how to avoid it? Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
On 15-5-2012 09:05, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
Hello,
I slightly modified the example - my code now is:
---- \ctxlua{os.execute([[echo lua -e "print 'WWW'"]])}
\starttext A \stoptext ----
So now I'm able to diagnose what exactly is passed to the command line.
I'm getting:
" .... languages > language en is active lua -e "print "WWW"" {c:/ConTeXt/tex/texmf-context/fonts/map/pdftex/context/mkiv-base.map} .... "
So it can be seen that [surprisingly] character ' was substituted for " - and IMHO this causes the problem.
Could anyone explain why this substitution is performed and how to avoid it?
probably some os.execute parsing ... does os.exec or os.spawn work ok? ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
probably some os.execute parsing ...
Do you mean Lua itself does the parsing and substitution? I guessed [lua]tex core... When I try to call on the command line: " C:\Lukas\ConTeXt\TestDDv>lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
os.execute([[lua -e "print 'WWW'"]]) WWW os.execute([[echo lua -e "print 'WWW'"]]) lua -e "print 'WWW'" =os.exec nil =os.spawn nil
" - There is no '/" substitution in standalone Lua (?!).
does os.exec or os.spawn work ok?
Well, the 'os.exec' works, in condition that it is called with "cmd /c": ---- \ctxlua{os.execute([[echo lua -e "print 'EXECUTE'"]])} \ctxlua{os.exec([[cmd.exe /c echo lua -e "print 'EXEC'"]])} \ctxlua{os.spawn([[cmd.exe /c echo lua -e "print 'SPAWN'"]])} \starttext A \stoptext ---- Gives: " ... languages > language en is active lua -e "print "EXECUTE"" lua -e "print 'EXEC'" system | total runtime: 0.609 " Interesting that the string to be passed to 'os.exec' keeps ' whilst that to 'os.execute' doesn't. Why this happens? Anyhow, thanks for the idea with 'os.exec'. Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
On 15-5-2012 10:34, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
languages > language en is active lua -e "print "EXECUTE"" lua -e "print 'EXEC'"
you can try texlua instead of lua to see what happens
system | total runtime: 0.609 "
Interesting that the string to be passed to 'os.exec' keeps ' whilst that to 'os.execute' doesn't.
Why this happens?
I dont' know. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
... I also tried: ---- \write18{echo 'AAA'} \starttext A \stoptext ---- Which gives: " ... backend > xmp > using file 'c:/ConTeXt/tex/texmf-context/tex/context/base/lpdf-pdx.xml' "AAA" pages > flushing realpage 1, userpage 1 ... " So it can be seen that ' changes to " even in this case. Weird. Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
![](https://secure.gravatar.com/avatar/386a116d129cdc597f2bb6210bbaff7a.jpg?s=120&d=mm&r=g)
On Tue, May 15, 2012 at 1:46 PM, Procházka Lukáš Ing. - Pontex s. r.
o.
... I also tried:
---- \write18{echo 'AAA'}
\starttext A \stoptext ----
Which gives:
" ... backend > xmp > using file 'c:/ConTeXt/tex/texmf-context/tex/context/base/lpdf-pdx.xml' "AAA" pages > flushing realpage 1, userpage 1 ... "
So it can be seen that ' changes to " even in this case. Weird. same here, with windows 7 home premium -- luigi
![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
... Finally, I use the following to avoid ' in arguments and to keep " to os.execute(): ---- \bgroup \catcode`\%=11 \ctxlua{os.execute(([[echo lua -e "print 'EXECUTE'"]]):gsub("'(.-)'", "[[%1]]"))} \egroup % Or: \startluacode os.execute(([[echo lua -e "print 'EXECUTE'"]]):gsub("'(.-)'", "[[%1]]")) \stopluacode \starttext A \stoptext ---- None of both solutions are "pure" as I'd imagine but they seem to work. Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
participants (3)
-
Hans Hagen
-
luigi scarso
-
Procházka Lukáš Ing. - Pontex s. r. o.