Richard H.Administrator
(KiX Supporter)
2001-05-03 04:30 PM
Read output from command as a pipe/file

I know OPEN() reads the entire file into memory, so would it be possible to capture the console output from a command started by SHELL and make the output available to READLINE()?

------------------

Richard Howarth

cj
(MM club member)
2001-05-03 07:03 PM
Re: Read output from command as a pipe/file

You can already by:

code:

Shell "cmd /c dir c:\ >file.txt"
$=open(1, "file.txt")
$text=""
do
$text=$text+readline(1)
until @error<>0
$=close(1)

but I know what you mean. What would be cool is to make SHELL a function instead of a command where the return value is the output of everything run in SHELL.

eg:
this is the new version of the above code:

$text=shell "cmd /c dir c:\*.txt"

This means that all your old scripts would need $= prepended to the SHELL commands, but I don't run .KIX files with K2k anyway, I call k2k scripts .K2K files instead.

Ruud, is this possible?


cj

Richard H.Administrator
(KiX Supporter)
2001-05-04 10:41 AM
Re: Read output from command as a pipe/file

The point is that READLINE() doesn't read from a file - it reads from an in memory buffer. This should mean that it is (hopefully!) trivial to capture the console output to the same buffer and use READLINE() in exactly the same way as you would if you'd read a file in.

One of the advantages is that you don't have to concern yourself with generating temporary files and the problems associated with it. A script becomes much more portable if you can keep it in-house.

Ideally we'd have proper file io and the ability to read from any io stream whether that be file, serial port, keyboard or command output. That however goes well beyond the scope of a scripting language whose original design purpose is logon processing

------------------

Richard Howarth

cj
(MM club member)
2001-05-05 11:28 PM
Re: Read output from command as a pipe/file

You can use OLE/COM to read from a text stream:

Have a look here and here. The second post shows accessing the FileSystemObject to write to a file. Later I will post some more COM code.

cj

cj
(MM club member)
2001-05-08 10:22 AM
Re: Read output from command as a pipe/file

Here is the FileSystemObject User's Guide from MSDN. This site also contains VBScript, JScript (MS's Java) and Remote Scripting. Here is the FileSystemObject Object page which lists all the Properties and Methods.

How to use FSO objects and methods in KiX COM:

This is the VBScript code to create a text file:

code:

Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)

This is the KiX2k equivalent.

code:

DIM $fso, $f1
$fso=CreateObject("Scripting.FileSystemObject")
$f1=$fso.CreateTextFile("c:\testfile.txt", "-1", "0") ; the 0 means false which means Not Unicode, ASCII instead. It is default and optional in VBS.

That creates a 0 byte text file and you can continue to access it with KIXCOM like this:

code:

$f1.WriteLine("This is a test.")
$f1.Close


cj


------------------
For more scripts goto cj's home page


chrismat@ozemail.com.au

 


[This message has been edited by cj (edited 08 May 2001).]