Page 1 of 1 1
Topic Options
#22224 - 2002-05-27 04:54 PM How to Grab 'Output' and Pipe to a file
Thinker Offline
Fresh Scripter

Registered: 2002-05-21
Posts: 10
Dear all,

I need to find a command line equivlant to unix.

#ls -al | grep drv > /test.txt

Meaning i wanna to grab some words from the output and pipe to a file.

Any advise would be appreciated.

Thanks in advance.

Top
#22225 - 2002-05-27 05:00 PM Re: How to Grab 'Output' and Pipe to a file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
To redirect outputs from KiXtart to a file you can use REDIRECTOUTPUT('c:\temp\text.txt') which will redirect everything that would normally go to the screen into the specified file. Please see the manual for a description of REDIRECTOUTPUT().
To redirect outputs from the command line (outside of KiXtart) you would use e.g. DIR >C:\TEMP\TEXT.TXT
_________________________
There are two types of vessels, submarines and targets.

Top
#22226 - 2002-05-27 06:01 PM Re: How to Grab 'Output' and Pipe to a file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
A couple of FAQs you may want to look at:

Topic: (almost) everything you wanted to know about RUN and SHELL

Topic: File Input/Output Primer
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22227 - 2002-05-27 07:48 PM Re: How to Grab 'Output' and Pipe to a file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
A couple of UDFs to look at as well.

Topic: Pipe - Submits a shell command and redirects output to an array

Topic: Pipe(2) - Submits a shell command and redirects output to an array
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22228 - 2002-05-30 03:34 PM Re: How to Grab 'Output' and Pipe to a file
Thinker Offline
Fresh Scripter

Registered: 2002-05-21
Posts: 10
Thanks for all advises.

I still cannot get it.

I am trying to perform a directory listing and pipe to a file.

How can i perform dir/w > c:\test.txt in kixtart?

Top
#22229 - 2002-05-30 03:37 PM Re: How to Grab 'Output' and Pipe to a file
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Here:
code:
SHELL "%comspec% /c dir /w > c:\test.txt"

Perhaps you meant using a kixtart "dir" or something else, but this is the easy way... just shell to a command prompt to do it. You must use the %comspec% to load the command prompt before running the dir and sending the output to a file.

Brian

Top
#22230 - 2002-05-30 03:37 PM Re: How to Grab 'Output' and Pipe to a file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
SHELL '%COMSPEC% /c /e:1024 dir /w >%TEMP%\test.txt'

Make sure you have the correct permisssions if really have to write into the root directory of Windows NT/2000/XP
_________________________
There are two types of vessels, submarines and targets.

Top
#22231 - 2002-05-30 03:38 PM Re: How to Grab 'Output' and Pipe to a file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Try:

shell '%comspec% /c dir /w > c:\test.txt'

-shawn

Top
#22232 - 2002-05-30 03:38 PM Re: How to Grab 'Output' and Pipe to a file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Damn, what's going on here? There are more and more posts arriving at the same time or maybe even just a minute apart.
_________________________
There are two types of vessels, submarines and targets.

Top
#22233 - 2002-05-30 05:19 PM Re: How to Grab 'Output' and Pipe to a file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Gee, Can I add my two cents? Am I too late?

First off, you're not piping, you're redirecting.
Instead of dir /w perhaps dir /b would be the better option. Don't know what you want to do with the output, but maybe piping would be the way to go. Take another look at Shawn's Pipe() UDF.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22234 - 2002-05-30 05:42 PM Re: How to Grab 'Output' and Pipe to a file
Thinker Offline
Fresh Scripter

Registered: 2002-05-21
Posts: 10
Thanks everyone for the prompt reply.

The answer is exactly what i need.

Cheers

Top
#22235 - 2002-05-30 05:47 PM Re: How to Grab 'Output' and Pipe to a file
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I decided to fiddle around a bit and see what I could do with KiXtart that looks sorta like dir /w ...

What I found is that KiXtart uses long file names, so the formatting is a bit tricky. Also, I didn't worry about sorting the names in alphabetical order, although it probably wouldn't be TOO difficult. If anyone would like to improve on this, go for it!

code:
break on
DIM $files[255]
$x=0
$y=0
$length = 0
$folder = "c:\"
$endfile = "C:\test.txt"

$files[$x] = DIR($folder)

While @error = 0
$x = $x + 1
$files[$x] = DIR()
$folderfile = $folder + $files[$x]
Loop

For each $file in $files
If $file <> ""
$y=$y+1
Endif
Next

REDIM PRESERVE $files[$y-1]

;Print Output

$length = 0
$lengtht = 0
DEL $endfile
$rc = RedirectOutput($endfile)

For each $file in $files

If GetFileAttr($folder + $file) & 16
$file = "[" + $file + "]"
Endif

While LEN($file) < 16
$file = $file + " "
Loop

While LEN($file) > 16 and LEN($file) < 32
$file = $file + " "
Loop

While LEN($file) > 32 and LEN($file) < 48
$file = $file + " "
Loop
While LEN($file) > 48 and LEN($file) < 64
$file = $file + " "
Loop


$length = $length + LEN($file)
;$lengtht = $lengtht + LEN($file)

if $length > 64 and $length < 80
?
$length = 0
Endif

;If $lengtht > 1840
; Get $_
; $lengtht = 0
;Endif

$file

Next
$rc=RedirectOutput("")

{edit}
This worked on a Windows 95 machine, but doesn't seem to work on NT.. at least not so far as the formatting is concerned. I believe this shouldn't be too hard to fix. Also, the array can be resized to accomodate larger directories.


Brian

[ 30 May 2002, 18:20: Message edited by: BrianTX ]

Top
#22236 - 2002-05-30 07:54 PM Re: How to Grab 'Output' and Pipe to a file
Rocco Capra Offline
Hey THIS is FUN
*****

Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
My .5 cent...


$F1 = Dir("%0\..\*.*")
$RC = Open(1,"%0\..\output\dir.txt",5)
WHILE $F1 <> "" and @ERROR = 0
$RC = WriteLine(1,'$F1' + @CRLF)
$F1 = Dir() ; retrieve next file
LOOP
$RC = Close(1)


Rocco
_________________________
I Love this board!! -------------------- My DEV PC is running KIX 4.22 WINXP Pro

Top
#22237 - 2002-05-30 08:08 PM Re: How to Grab 'Output' and Pipe to a file
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Yeah. that's easy enough, Rocco.. however it doesn't do the /w format.. but just line by line.. nor does it differentiate files from folders.

Brian

Top
#22238 - 2002-05-30 08:31 PM Re: How to Grab 'Output' and Pipe to a file
Rocco Capra Offline
Hey THIS is FUN
*****

Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
Yeah I know thats why its only worth .5 cent

[Wink]
_________________________
I Love this board!! -------------------- My DEV PC is running KIX 4.22 WINXP Pro

Top
Page 1 of 1 1


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

Who's Online
0 registered and 857 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.102 seconds in which 0.062 seconds were spent on a total of 11 queries. Zlib compression enabled.

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