Run a newLISP script as a Windows batch file: FINAL

Started by alex, February 10, 2012, 07:57:42 AM

Previous topic - Next topic

alex

For Windows 2000 and more You can add ONLY ONE short string before newLISP text.

Example:

file HelloWorld.cmd contain

@newlisp.exe %0 %* & goto :EOF
# begin newlisp-program
(println "Hello World!")
(exit)
# end newlisp-program
:-)



Correction 2012.02.21

First string must be
@newlisp.exe "%~f0" %* & goto :EOF

Such variant allow run HelloWorld.cmd from command line without extention ".cmd", and fix problem, when full path to HelloWorld.cmd contain spaces.

newdep

#1
Nice catch , I thought i give it a try but on my win7 it jumps right over the newlisp program into the newlisp prompt.

I too was this week seeking for a clean execute solution too on windows,

as on OS/2 i can use the COMSPEC= that cant be used under windows..



I have seen some perl examples doing these tricks but not very delightful

perhpas i run into another solution as this example is 99% close ;-)
-- (define? (Cornflakes))

newdep

#2
A correction here to be made alex! It does work!



The .BAT version on my Win7 runs directly into a newlisp prompt but the .CMD works! .. Thanks!
-- (define? (Cornflakes))

xytroxon

#3
I'm confused...



Did you have problems with using this version in Code Snippets?



-- xytroxon



----------------------------------



Code Snippets

http://www.newlisp.org/index.cgi?page=Code_Snippets">//http://www.newlisp.org/index.cgi?page=Code_Snippets



Run a newLISP script as a Windows batch file



REM posted by Alex, adjusted by Fred
REM
@goto RUNLISP
(println "Hello World!")
(exit)
:RUNLISP
@if "%newlisp%" == "" set newlisp=newlisp.exe
@if "%OS%" == "Windows_NT" %newlisp% %0.bat %*
@if not "%OS%" == "Windows_NT" %newlisp%
            "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

alex

#4
2 xytroxon

It was good variant, when I used Win2k and Win98 together. New variant is simpler, I think.

alex

#5
I don't knew, who tuning "Code Snippets", but, please, correct first string and specify, that extension of batch-file MUST be ".cmd"

Lutz

#6
Not sure what you mean. Can you post the corrected script snippet?

Lutz

#7
Either leaving how it is, or replacing 0.bat with 0.cmd and changing the script extension itself to .cmd, will print comments and "Hello world!" three times to the terminal, then not exit but stay in newLISP on XP SP2.



The simpler script in "Code Snippets" also does not work, not doing anything, also staying in newLISP. Perhaps we should delete the whole thing. If it works only on Windows 7 we should say so.

alex

Run a newLISP code as ".cmd"-file(Windows 2000 and more)

@rem Posted by alex from newlisp.org
@newlisp.exe "%~f0" %* & goto :EOF
# begin newlisp-program
(println "Hello World!")
(exit)
# end newlisp-program

alex

#9
only .cmd - not .bat

Lutz

#10
This one too with a .cmd extension does not work on Windows XP SP2.


ERR: missing parenthesis : "...@rem Posted by alex from newlisp.org"

Is this only for Windows 7 ?

alex

#11
I am sorry, smile is bad. I will correct...

Lutz

#12
Thanks, this one works fine on XP.

alex

#13
All o'k, thank You Lutz!

xytroxon

#14
Quote from: "alex"Run a newLISP code as ".cmd"-file(Windows 2000 and more)

@rem Posted by alex from newlisp.org
@newlisp.exe "%~f0" %* & goto :EOF
# begin newlisp-program
(println "Hello World!")
(exit)
# end newlisp-program


The Windows cmd-exe parser skips leading whitespace, defined as semicolons, tabs, commas, and spaces, so you can safely embed cmd.exe commands as newlisp comments...



; @rem Posted by alex from newlisp.org
; @newlisp.exe "%~f0" %* & goto :EOF
# begin newlisp-program
(println "Hello World!")
(exit)
# end newlisp-program


-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976