#22224 - 2002-05-27 04:54 PM
How to Grab 'Output' and Pipe to a file
|
Thinker
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
|
|
|
|
#22228 - 2002-05-30 03:34 PM
Re: How to Grab 'Output' and Pipe to a file
|
Thinker
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
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
|
|
|
|
#22234 - 2002-05-30 05:42 PM
Re: How to Grab 'Output' and Pipe to a file
|
Thinker
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
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
|
|
|
|
#22237 - 2002-05-30 08:08 PM
Re: How to Grab 'Output' and Pipe to a file
|
BrianTX
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 857 anonymous users online.
|
|
|