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

Can .Exec be called hidden?

11,191 views
Skip to first unread message

Csaba2000

unread,
Mar 26, 2003, 7:42:34 PM3/26/03
to
I have a script which needs some return (string) information from another
app.
This works fine using:

'path contains the full path to a file
phpExec1 = "c:\Winapps\PHP\4.3\cli\php.exe -r ""print filemtime('" & path &
"');"""
set wShell = CreateObject("WScript.Shell")
set resExec = wShell.Exec (phpExec1)
ftime = resExec.StdOut.ReadAll()

The only problem is that I get flashes on the screen as a command prompt is
opened
for each invocation of the above call. And, per MIB, I don't like to be the
object of
flashy thingies.

I could use .Run to run quietly without disturbing the peace,
and save the information to a file, but this strikes me as UGLY.
I couldn't figure out how to have .Run set an environment variable that my
.vbs file
could slurp up.

Is there some way that I can have my .Exec call run hidden or some
reasonable
way to get information back from the .Run so I can have my cake and eat it,
too?

Thanks,
Csaba Gabor from New York


Torgeir Bakken (MVP)

unread,
Mar 26, 2003, 8:22:02 PM3/26/03
to
Csaba2000 wrote:

> (snip)


> I could use .Run to run quietly without disturbing the peace,
> and save the information to a file, but this strikes me as UGLY.
> I couldn't figure out how to have .Run set an environment variable that my
> .vbs file could slurp up.

Environment changes done by child processes are not seen by the parent.


> Is there some way that I can have my .Exec call run hidden

Nope.


> or some reasonable
> way to get information back from the .Run so I can have my cake and eat it,
> too?

Saving results to a file is usually the way to go here, and I have no problem
about doing it ;-)


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


BitsNotBytes

unread,
Mar 27, 2003, 9:54:14 AM3/27/03
to
Some ideas:

Use a BAT file to set the environment variables and any subsequent
CALL statements to other exe's such as cscript should see the same
environment variables. AFAIK any cscript should be able to manipulate
the environment variables and make them 'seen' to any other subsequent
cscript in the same bat file. At best you should be able to reduce
the 'flashing' to the task bar using .bat, start /min, .lnk. You
could use WMI to start a process directly which hides it from the task
bar.

BitsNotBytes


"Csaba2000" <ne...@CsabaGabor.com> wrote in message news:<egVrQk$8CHA...@TK2MSFTNGP12.phx.gbl>...

Alex K. Angelopoulos (MVP)

unread,
Mar 29, 2003, 6:02:51 AM3/29/03
to
Torgeir Bakken (MVP) wrote:

> Csaba2000 wrote:
>
> Saving results to a file is usually the way to go here, and I have no
> problem about doing it ;-)

This is an EVERY day question now. Here's a quick list of the variations on
that while I'm thinking about it...

+ Write to file is the good, works even with earlier versions of WSH, and
Michael Harris has a complete wrapper class for it on Clarence's site.

+ A really UGLY solution is to use exec anyway and then use a control like
AutoItX to hide the resulting window; you normally get momentary screen popup
with this.

+ A cleaner programmed solution is to use a component that wraps up named pipes
for use from script, then pipe the output; requires install of a control like
the prior solution, but there is no text file read-write step.

--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com
(email requests for support contract information welcomed)
----------
Microsoft's new UNIFIED Terminal Services Newsgroup:
news:microsoft.public.windows.terminal_services

Christoph Basedau

unread,
Mar 30, 2003, 7:59:55 PM3/30/03
to
am 27.03.03 01:42 sprach Csaba2000 dieses:

Yes there is a way:
Call the app with the flashing console-window from a second script
where you call it with "wshShell.run cmd,0,true". Pass the cmdLine
from the first Script and start it with:
set oExec = WSHShell.Exec ("Wscript.exe secondScript.vbs " & cmdLine)
and catch oExec.StdOut then.
It's almost the same, but no flashes.
You can use the second Script to hide and catch the Stdout
of any console window, so it's really reusable.

mfg
Christoph


Example:

'----------------
'Calling Script
cmd = "ping -n 2 www.google.ru" 'put your lengthy PHP-Cmd here
callee = "StdoutCatcher.vbs"
wrappedCmd = "WScript.exe " & callee & " """ & cmd & """"

Set oWS = CreateObject("WScript.Shell")
With oWS.Exec (wrappedCmd)
Do Until .status: WScript.sleep 33 : Loop
iRet = .exitcode
If iRet = 0 Then
strFullStdOut = .StdOut.ReadAll()
msgbox strFullStdOut
Else
msgbox "Error executing: " & vbCr & cmd & "Errorcode: " & iRet
End If
End With
'----------------

'----------------
'Name: StdOutCatcher.vbs, Hides the console passed as %1
With WScript.Arguments.Unnamed
if .count = 0 then WScript.Quit 1 'indicating missing arg
cmd = .item(0)
End with
Set oWS = CreateObject("WScript.Shell")
On Error Resume Next
oWS.Run cmd, 0, true 'that's how the console is hidden
WScript.Quit Err.number 'return an exitcode to the calling script
'---------------------------

Alex K. Angelopoulos (MVP)

unread,
Mar 30, 2003, 8:52:10 PM3/30/03
to
Christoph Basedau wrote:

> Yes there is a way:
> Call the app with the flashing console-window from a second script
> where you call it with "wshShell.run cmd,0,true". Pass the cmdLine
> from the first Script and start it with:
> set oExec = WSHShell.Exec ("Wscript.exe secondScript.vbs " & cmdLine)
> and catch oExec.StdOut then.
> It's almost the same, but no flashes.
> You can use the second Script to hide and catch the Stdout
> of any console window, so it's really reusable.


Now THAT is clever.

Csaba2000

unread,
Apr 11, 2003, 4:56:58 PM4/11/03
to
Hi Christoph,

It is only now that I see your reply (and I appreciate all the
responses).
I have tried your script, and many variants on my machine, but in every
case,
strFullStdOut is empty. The same goes for .StdErr.ReadAll()

Could it be that this is because I am on a Win2K Pro system?
When I try putting CScript.exe in place of WScript.exe in wrappedCmd,
then strFullStdOut shows me the standard CScript greeting:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

My conclusion is that my output is not getting pumped into StdOut.

I have tried your ping as is.
I tried with my phpExec1 command.
I also tried:
comspec = oWS.ExpandEnvironmentStrings("%COMSPEC%")
cmd = comspec & " /c dir"
In all cases I got a blank MsgBox

Any ideas?
Thanks,
Csaba Gabor

"Christoph Basedau" <cebit_...@gmx.net> wrote in message
news:utcaBEy9...@TK2MSFTNGP11.phx.gbl...

Csaba2000

unread,
Apr 13, 2003, 1:30:34 AM4/13/03
to
I bet nobody even reads posts started more than two weeks ago...
but the upshot is that I couldn't make your suggestion work out
as it was given, Cristoph, but by diving into some of your older
posts and even a two year old one from Michael Harris I finally
synthesized a single .vbs file demonstrating what I was looking for:
a way to call a (PHP) program via a hidden command window and to
return its output:

Set oWsh = WScript.CreateObject("WScript.Shell")
if IsWScript() Then
oWsh.Run "Cscript.exe //NOLOGO " & WScript.ScriptFullName,0,true '0 => hide; true => sychronous
foo = oWsh.Environment("volatile")("foo") 'Pick up the console output here
oWsh.Environment("volatile").remove("foo") 'Clean up in case of DOS calls
msgBox "Just Waiting: " & vbcrlf & foo 'The proof
Else
cmd = "dir" 'For those people without php
mypath = WScript.ScriptFullName 'example file to get the date of
cmd = "c:\Winapps\PHP\4.3\cli\php.exe -r ""print filemtime('" & mypath & "');""" 'filetime of ourself
Set oExec = oWsh.Exec("%comspec% /c " & cmd) 'Run the dos command
Do Until oExec.status: WScript.Sleep 33: Loop 'Wait until it's done
Input = oExec.StdOut.ReadAll() 'Get the dos command's output
oWsh.Environment("volatile")("foo") = Input 'Prepare it for pickup by the caller
End If

Function IsWScript()
IsWScript = false
If Instr(UCase(WScript.FullName), "WSCRIPT") Then IsWScript = true
End function

Thanks for the tips,


Csaba Gabor from New York

"Csaba2000" <ne...@CsabaGabor.com> wrote in message news:OWctywG...@TK2MSFTNGP12.phx.gbl...

Paul Randall

unread,
Apr 14, 2003, 1:14:41 PM4/14/03
to
Csaba2000 wrote:
> I bet nobody even reads posts started more than two weeks ago...

Hi, Csaba200
If nobody read this, he/she would have responded.
I'm not nobody.

-Paul Randall


Alex K. Angelopoulos (MVP)

unread,
Apr 16, 2003, 3:08:06 AM4/16/03
to
Besides, nobody usually posts in .termserv.*...

I forget where 'who' posts.

--

djspamm...@gmail.com

unread,
Oct 26, 2012, 9:30:56 AM10/26/12
to
0 new messages