Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Command line input to CScript/WScript?

311 views
Skip to first unread message

Csaba Gabor

unread,
Apr 24, 2005, 8:15:53 AM4/24/05
to
Is there a way that I can give CScript and WScript a command
line argument (as opposed to a .vbs file) of the script that
I want it to execute?

This question may seem somewhat odd so let me say what
I'm really after. I want to get the output of the ver
command to my script. And I don't want any screen
flicker that you normally get with .Exec

Now there's a way to do this which involves having CSCript
call WScript in a hidden window so that the output can
be returned to CScript through a volatile environment
variable (March 26, 2003 thread: Can .Exec be called hidden).
http://groups-beta.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/54d3df2e29211bad/

However, I wish to do this without having a .vbs file on disc.
The reason is that the call is actually being made from
another program (PHP) which might not have write privileges
even though it can do .Run and .Exec

Hope this makes sense,
Csaba Gabor from Vienna

PS. Examples of PHP attempts that don't work:

$ver = shell ("ver"); // returns the output of ver from CMD window

If PHP is invoked through the windows interface (as opposed to a
cmd window) then the above PHP line or below code both produce a flicker.

<?php
$oWSH = new COM("WScript.Shell");
$oExec = $oWSH->Exec("%comspec% /c ver"); // execute the command
while (!$oExec->status) usleep(500); // wait for it to return
$ver = $oExec->StdOut->ReadAll(); // get the output
$oWSH->Popup($ver, 4, "Ver result", 131120); // display it
?>

Michael Harris (MVP)

unread,
Apr 24, 2005, 4:53:12 PM4/24/05
to
Csaba Gabor wrote:
> Is there a way that I can give CScript and WScript a command
> line argument (as opposed to a .vbs file) of the script that
> I want it to execute?
>
> This question may seem somewhat odd so let me say what
> I'm really after. I want to get the output of the ver
> command to my script. And I don't want any screen
> flicker that you normally get with .Exec

You can pipe or redirect the output of a command into cscript.exe which will
then make that standard input stream available to the executed script via
the wscript.stdin textstream...

ver | cecript.exe "c:\my path\muscript.vbs"

'=== myscript.vbs ===

set stdin = wscript.stdin

for each line in split(stdin.readall,vbcrlf)
wscript.echo "==>", line
next


>
> Now there's a way to do this which involves having CSCript
> call WScript in a hidden window so that the output can
> be returned to CScript through a volatile environment
> variable (March 26, 2003 thread: Can .Exec be called hidden).
> http://groups-beta.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/54d3df2e29211bad/
>
> However, I wish to do this without having a .vbs file on disc.
> The reason is that the call is actually being made from
> another program (PHP) which might not have write privileges
> even though it can do .Run and .Exec
>


You could also use a genric internal routine that uses WshShell.Run to run
the command in a hidden window with output redirtected to a file that is
then read/parsed.

Plenty of vbscript examples can be found via google

Google Search: doscmd OR runcmd
http://groups-beta.google.com/groups?q=doscmd+OR+runcmd+group%3A*.scripting&qt_s=Search


--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.

Michael Harris (MVP)

unread,
Apr 24, 2005, 5:40:24 PM4/24/05
to
>
> You can pipe or redirect the output of a command into cscript.exe
> which will then make that standard input stream available to the
> executed script via the wscript.stdin textstream...
>
> ver | cecript.exe "c:\my path\muscript.vbs"

Typo:

ver | cscript.exe "c:\my path\muscript.vbs"


>
> '=== myscript.vbs ===
>
> set stdin = wscript.stdin
>
> for each line in split(stdin.readall,vbcrlf)
> wscript.echo "==>", line
> next
>

0 new messages