How to access rsults of command line commands without pipig to a file?

How to access rsults of command line commands without pipig to a file?

Post by CM » Wed, 01 Sep 2004 07:37:10


Is there a way to issue a commandline command e.g. "quser" and retrieve and
process the results internally in the script, without having to pipe the
results to a file first and then read the file back into the script, to
process the results??

Any help is much appreciated.

Thanks ...CM
 
 
 

How to access rsults of command line commands without pipig to a file?

Post by Al Dunbar » Wed, 01 Sep 2004 08:52:14


and

You should be able to pipe the output of the command into the script with
something along these lines in a batch file:

quser | cscript //nologo yourscript.wsf

Your script would read the standard input using the .stdin property of the
wscript object (see the docs).

While this would seem to answer your question, it puts control of the
process in a batch file rather than your wsh script. If you need more
control, I think the only thing for it is to do what you appear not to like
to do. But it needn't be that messy if you bundle the functionality into a
function. I wrote one that returns the output of the command line passed as
a parameter, i.e.:

quserResult = cmd("quser")

The function looks after running the command via %comspec%, piping the
output to a %temp% file. When the command completes, it opens the temp file,
reads it in with .readall, closes, and deletes the file.


/Al

 
 
 

How to access rsults of command line commands without pipig to a file?

Post by CM » Wed, 01 Sep 2004 11:46:48


like
as
file,
Thanks Al. I will investigate this path. I was already resigned to writing
a function, although I really would like to be able to get this kind of info
without using file I/O.

The script issue that really started this was that I want to be able to get
information on the current users with active or disconnected terminal server
sessions on a server trough a login script. Do you know of any WMI queries
that can return the same info that the query user or qwinsta commands
return??

Thanks ...CM
 
 
 

How to access rsults of command line commands without pipig to a file?

Post by Al Dunbar » Thu, 02 Sep 2004 11:49:01


retrieve
the
to
with
the
a
writing
info

I know what you mean. But, whatever you do, somewhere there is disk IO
happening. Once you have coded a function to do this, you can use it to your
heart's content and forget about the underlying i/o that makes it work --
assuming your code will avoid temp filename collisions and remember to
delete the file when done. ;-)

get
server
queries

I'm not really a WMI expert (though others here are). I usually just play
with the scriptomatic tool looking to see what info it provides.

/Al