select script engine in script
select script engine in script
(OP)
Hi,
I want to write some console scripts that will need stdio, so they have to run in cscript rather than wscript. I want to be able to run the scripts by typing their name plus arguments at the command line.
Is it possible to specify in the script which engine to use? If possible, I would prefer to avoid using a .wsh file, registering a default engine through the //E argument to cscript, or sending my script as an argument to cscript.
I'm not worried whether I use vbscript, jscript or some other.
Any help appreciated.
I want to write some console scripts that will need stdio, so they have to run in cscript rather than wscript. I want to be able to run the scripts by typing their name plus arguments at the command line.
Is it possible to specify in the script which engine to use? If possible, I would prefer to avoid using a .wsh file, registering a default engine through the //E argument to cscript, or sending my script as an argument to cscript.
I'm not worried whether I use vbscript, jscript or some other.
Any help appreciated.
RE: select script engine in script
'Force a cscript host
force_cscript
sub force_cscript
dim args : args=""
dim i, wshshell
If right(lCase(wscript.fullname),11)= "wscript.exe" then
for i=0 to wscript.arguments.count-1
args = args & wscript.arguments(i) & " "
next
set wshshell=createobject("wscript.shell")
wshshell.run wshshell.ExpandEnvironmentStrings("%comspec%") & _
" /c cscript.exe //nologo """ & wscript.scriptfullname & """" & args 'change to /k for stay
set wshshell=nothing
wscript.quit
end if
end sub
Feel free to add other switches to cscript like " //b " after cscript.exe appeared in the .run line.
RE: select script engine in script
Sorry I didn't spot it in wherever the other thread is.