Page 1 of 1 1
Topic Options
#80060 - 2001-05-03 04:30 PM Read output from command as a pipe/file
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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

Top
#80061 - 2001-05-03 07:03 PM Re: Read output from command as a pipe/file
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
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

Top
#80062 - 2001-05-04 10:41 AM Re: Read output from command as a pipe/file
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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

Top
#80063 - 2001-05-05 11:28 PM Re: Read output from command as a pipe/file
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
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

Top
#80064 - 2001-05-08 10:22 AM Re: Read output from command as a pipe/file
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
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).]

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 142 anonymous users online.
Newest Members
KatieQuinn, Brennnnn, MKubicsek, xguixa, mdress
17681 Registered Users

Generated in 0.032 seconds in which 0.012 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