Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select script engine in script 2

Status
Not open for further replies.

SimonSellick

Programmer
Joined
Nov 3, 2003
Messages
305
Location
GB
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.
 
This is the standard device to force a hosting by cscript despite all oddity. Add the sub force_cscript and place a call to it at the top of the script. (I think I had long time ago posted something similar to a similar thread.)
[tt]
'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
[/tt]
Feel free to add other switches to cscript like " //b " after cscript.exe appeared in the .run line.
 
Thank you - have a star!

Sorry I didn't spot it in wherever the other thread is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top