Page 1 of 2 12>
Topic Options
#86076 - 2002-06-13 09:55 PM WSH Shell Piper
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is a script that pipes an error message using WSH. It's pretty cool because it doesn't use temp files or reg entries. Try it out and see what you think. If you guys like it, I'll turn it into a UDF.

code:
; Pipe.kix
;
Break On
$shellcmd="%comspec% /c dir *.kix"
$WshShell=CreateObject("WScript.Shell")
$oExec=$WshShell.Exec($shellcmd)

While $Exit<>1
Dim $Output
$Output=ReadAll($oExec)
If $Output=-1
If $oExec.Status=1
$Exit=1
endif
Else
? $Output
endif
Loop

? "Exit Code: "+$oExec.ExitCode

Function ReadAll($oExec)
If Not $oExec.StdOut.AtEndOfStream
$ReadAll=$oExec.StdOut.ReadAll
Exit
endif
If Not $oExec.StdErr.AtEndOfStream
$ReadAll=$oExec.StdErr.ReadAll
Exit
endif
$ReadAll=-1
EndFunction


Top
#86077 - 2002-06-13 09:59 PM Re: WSH Shell Piper
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
do it!!!

Is it any slower?
Does it open a cmd window? if not, is all the output is 'surpressed'/held internally?

does it pipe all normal output?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86078 - 2002-06-13 10:00 PM Re: WSH Shell Piper
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Oh man ... that is sweet !!!

Run .. Do not walk ... to the UDF forum ... do not pass GO ... collect $200 ...

[ 13 June 2002, 22:03: Message edited by: Shawn ]

Top
#86079 - 2002-06-13 10:02 PM Re: WSH Shell Piper
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Its pretty quick.

It does not open a command window.

Output is held internally in the oExec object, then parsed out with the $ouput string. However, when I ran another KiX script with this it didn't display the output. DOS command ouput displayed fine.

Top
#86080 - 2002-06-13 10:05 PM Re: WSH Shell Piper
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
would this be like...

$result=wmicmd($command,$some options)

where $result[0] is the normal output and $result[1] is the error out?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86081 - 2002-06-13 10:07 PM Re: WSH Shell Piper
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I agree as well. Publish [Big Grin]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#86082 - 2002-06-13 10:12 PM Re: WSH Shell Piper
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I just went looking for "wmicmd" and could not find it. The only reference that search engine found was in this thread.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#86083 - 2002-06-13 10:12 PM Re: WSH Shell Piper
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
In trekkie speak...
Make it so!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#86084 - 2002-06-13 10:16 PM Re: WSH Shell Piper
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
crap - think this needs a little further investigation. I just ran this on my XP just fine - but when I tried on NT4 SP6a with IE4 (I know, I know) and Office 97 ... the Exec method doesn't seem to be suported ... wonder if requires a certain (newer) version of WSH ?

[ 13 June 2002, 22:31: Message edited by: Shawn ]

Top
#86085 - 2002-06-13 10:19 PM Re: WSH Shell Piper
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Upgrade WSH 5.6

Windows Script Host 5.6 Boasts Windows XP Integration, Security, New Object Model

[ 13 June 2002, 22:21: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#86086 - 2002-06-13 10:22 PM Re: WSH Shell Piper
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
it works on my win2k sp2 IE6...

I Like it!!!
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86087 - 2002-06-13 10:23 PM Re: WSH Shell Piper
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just tried this, works like a champ man, this is sweet:

break on

$shellcmd="%comspec% /c dir *.kix"

$WshShell=CreateObject("WScript.Shell")

$oExec=$WshShell.Exec("$shellcmd")

for each $line in split($oExec.StdOut.ReadAll,chr(10))
 ?"line=" $line
next

exit 1


Top
#86088 - 2002-06-13 10:26 PM Re: WSH Shell Piper
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Do I smell a WshPipe() coming on, Chris ?
Top
#86089 - 2002-06-13 10:28 PM Re: WSH Shell Piper
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Took me some time to see what it does, but it is impressive!! I know i'll use this functionality!
_________________________
Kind regards,

Top
#86090 - 2002-06-13 10:30 PM Re: WSH Shell Piper
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Oh yeah! Shawn, did you have to update WSH? How does your code affect my script (haven't had time to test yours yet)?
Top
#86091 - 2002-06-13 10:34 PM Re: WSH Shell Piper
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Chris, like Howard mentioned, seems one would need WSH 5.6 for this - not too sure what version I have on my older system here - was just doing a bit of regression testing with your script, thats all.

The only reason I posted the other fragment was because I was trying to sort out, in my own mind, how this string got returned from ReadAll - and what was being used as the delimiter.

Top
#86092 - 2002-06-13 10:45 PM Re: WSH Shell Piper
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I see.

Yeah, the ExitCode property was added with 5.6. With WSH 5.6 it is now possible to 1) Run a script on your computer that 2) loads a script from a second and 3) runs it on a third computer. [Eek!]

{Edit} Oh, and 5.6 comes with IE6.

[ 13 June 2002, 22:47: Message edited by: Chris S. ]

Top
#86093 - 2002-06-13 10:51 PM Re: WSH Shell Piper
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jim (jtokach) did you hear that one ?

Topic: Remote Execution - Driving me insane!

Top
#86094 - 2002-06-13 11:01 PM Re: WSH Shell Piper
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
just from the code that shawn posted I slammed this together, but I don't know enought to handle the error channel and such...

or the best way the pass the return back.

code:
break on

$return=WSHPipe("dir \\a06\logon\*.kix")
? $return

$pipearray=split($return,chr(10))
for each $line in $pipearray
? "."+$line
next

get $k
quit
;******************************************************************
function WSHPipe($cmd, Optional $environment)
if $environment
$cmd="/e $environment $cmd"
endif
$cmd="%comspec% /c "+$cmd
$WshShell=CreateObject("WScript.Shell")
$oExec=$WshShell.Exec("$cmd")
$WSHPipe=$oExec.StdOut.ReadAll
$WSHPipeErr=$oExec.StdErr.ReadAll
endfunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86095 - 2002-06-13 11:11 PM Re: WSH Shell Piper
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I couldn't get the correct error code until I parsed through the oExec object. Thus, the need for the ReadAll function.
Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.049 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org