Page 1 of 1 1
Topic Options
#62540 - 2002-01-30 11:47 AM Redirecting command output...
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
'smorgens

Got a little question on the redirection of command output. I want to use the "use list" command to find out what drives are currently mapped. i would love to be able to use syntax like :
$result = split((use list),chr10)
to have all the lines in an array called $result.
I noticed that there were already some entries in the suggestions forum about redirecting in this way and also for shell output. let's hope it'll bee incorporated soon. In the mean time i could use redirectoutput and read the txt file. The following code :
redirectoutput("uselist.txt",1)
use list
redirectoutput("")
the txt file that is generated does not recognize the eol characters correctly, dumping all output to one line with two unreadable chars between lines.
Is that a problem with my setup or does anybody else also have problems with that ???
I use WIn2K prof SP1, Kix 4.02 and Notepad.exe V5.0.2140.1

Any input/help would be appreciated...

_________________________
rgrds, Maarten

Top
#62541 - 2002-01-31 12:00 AM Re: Redirecting command output...
Sergie Offline
Fresh Scripter

Registered: 2002-01-30
Posts: 17
Loc: Moscow
That is a problem of Notepad. Sometime it recognizes text files as binary. I cannot understand why.
Top
#62542 - 2002-01-30 01:29 PM Re: Redirecting command output...
Will Hetrick Offline
Hey THIS is FUN

Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
MVDW,

How about adding a line to the redirect output

ex:

code:
 
redirectoutput("uselist.txt",1)
use list ?
redirectoutput("")


_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!

Top
#62543 - 2002-01-30 02:53 PM Re: Redirecting command output...
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
Will,
your suggestion didn't help, somehow it does place the EOL chars in the file, but Notepad doesn't recognize them as Sergie mentioned.
I tested with :
redirectoutput("uselist.txt",1)
use list
redirectoutput("")
if open (1,"uselist.txt") = 0 endif
while @error = 0
$line = readline(1)
$line ?
loop

that does display them line by line.

Sergie, do you know of any documentation about this weird problem ??
It doesn't really matter for script execution but it is annoying...
Wordpad does recognize them..

[ 30 January 2002: Message edited by: mvdw ]

_________________________
rgrds, Maarten

Top
#62544 - 2002-01-30 03:05 PM Re: Redirecting command output...
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
Guys,

if i open the file in wordpad, and then save as "Text Document - MS DOS Format" it will display correctly in Notepad.

I found an interesting discussion (of which i do not understand most here about this problem. Since i do no not know anything about the KIX internals, maybe someone who does can shed a light on this ???

_________________________
rgrds, Maarten

Top
#62545 - 2002-01-30 03:16 PM Re: Redirecting command output...
Will Hetrick Offline
Hey THIS is FUN

Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
If it does not matter if you use wordpad or Notepad, Change your test file to say uselist.doc and when you doubleclick it it will open in word/wordpad. I also got rid of the leading 0 using this code.

code:
 
$x = ReDirectOutput("uselist.doc",1)
Use list
$x = ReDirectOutput("")

_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!

Top
#62546 - 2002-01-30 03:22 PM Re: Redirecting command output...
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
That is true will, but...
i don't even really need to open it anyway. opening it using the open function in kixtart doesrecognize them correctly.
Just thought that it might be nice to have redirectoutput create text files in a way that notepad recognizes...
in the link i added they mention something about a difference in /r and /n endings.
Dunno what that means but i can imagine that the way redirectouput and perhaps the use list commands use line endings is not consistent within kix.
_________________________
rgrds, Maarten

Top
#62547 - 2002-01-30 03:54 PM Re: Redirecting command output...
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
I think i sort of got it now...
i copy pasted the characters from notepad to a script to ASC("") them and they were all chr(10). then i used the following code :
code:

redirectoutput("uselist.txt",1)
use list
redirectoutput("")
if open (1,"uselist.txt") = 0 endif
if open (2,"testoutput.txt",5) = 0 endif
$line = readline(1)
while @error = 0
$line = $line + chr(13) + chr(10)
$rc = writeline(2,$line)
$line ?
$line = readline(1)
loop


to manually add the chr(13) before and then it opens normally in notepad.

Now the question is, why does the use list "forget" to add the chr(13) to the end of each line ??? or is it intended to ?
are there more commands that have this problem ?? i have never seen it happen when using dos redirection with ">"

_________________________
rgrds, Maarten

Top
#62548 - 2002-01-30 04:20 PM Re: Redirecting command output...
Sergie Offline
Fresh Scripter

Registered: 2002-01-30
Posts: 17
Loc: Moscow
Maarten
I use Textpad editor (www.textpad.com).
It is shareware and has syntax definitions for KIX.

Sergie

Top
#62549 - 2002-01-30 04:37 PM Re: Redirecting command output...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
are you sure it is use list thing. what about using some other lists.
like net view?
it might also be kix's redirect thing...
_________________________
!

download KiXnet

Top
#62550 - 2002-01-30 05:04 PM Re: Redirecting command output...
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
Lonkero,

i thought about that too, but if i shell a net view, output returned is "0" for the correct calling of shell command. And as i said, the problem does not occur on the dos ">" redirector.

i couldn't find another kix native command with multiple lines output. Maybe you know one ??

Or maybe one who knows the exact internals of kix (...) can explain if it is in the redirectoutput or in use list...

_________________________
rgrds, Maarten

Top
#62551 - 2002-01-30 05:17 PM Re: Redirecting command output...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
use...
I quess it is it.
cause redirecting kix to file, if i've understood right, redirects the same what is output on the screen.
so, it might be, ruud or someone can correct me, that use list has only chr(10) in build, cause it is supposed to be used inside kix and for view in kix window.
you might want to ask this same question also (or just point to this topic) in the beta forum.
'cause if this is the case it should be informed in the doc or the behaviour should be changed 'cause it's unexpected.

cheers,

_________________________
!

download KiXnet

Top
#62552 - 2002-01-30 06:04 PM Re: Redirecting command output...
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It's probably just the age old problem of binary versus ascii output for DOS IO.

Try this:

code:
"This line contains only a chr(10) " chr(10) "in the middle" ?

Now, if the output is binary i.e. exactly what you are attempting to send, then the "in the middle" part of the string would start on the next line, one space to the right of the first part of the string. It doesn't though, it starts at the beginning of the next line.

This is because the console output is an ASCII stream, and converts CHR(10)->CHR(13)+CHR(10).

If the output stream is binary then the conversion is not done - this would be the case where you want to copy a file for instance.

Unfortunately due to a moment of extreme madness when DOS was being cobbled together, the engineers decided to use CHR(13)+CHR(10) as the end-of-line sentinel for DOS IO, and programmers have been cursing them for it since that day.

So, it depends on what you intend to use the data for whether the data will be binary or ASCII. In the DOS world the programmer will have to guess, and it will be wrong for someone.

Here is a good example of how it breaks things.
I have a file with 3 lines in it, each containing the number 1-3 in reverse order, the lines are seperated by CHR(10). If I "type" the file I get:

code:
3
2
1


So, "type" is preserving the information in the file - it is displaying it exactly as it is. What if I "sort" the file? Now I get:
code:
1
2
3


So the "sort" has converted my data - it has changed the end-of-line characters and inserted CHR(13)s.

So, sometimes the CHR(10)s are converted and sometimes not. It is down to the individual programmer to decide which is correct for each situation.

Personally I think you should always preserve the integrity of the data stream unless you are outputtiing it to a rendering device such as the screen of printer.

[ 30 January 2002: Message edited by: Richard Howarth ]

Top
#62553 - 2002-01-30 06:12 PM Re: Redirecting command output...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
richard, the problem was that this is not dos thingie. it's internal kix problem.
so why should kix have same problems as dos?
_________________________
!

download KiXnet

Top
#62554 - 2002-01-31 02:16 AM Re: Redirecting command output...
Anonymous
Unregistered


This is a very old pain on the ... !

It is because the way some guys at microsoft have written their programs !!! In fact there are many command line utilities that their end of line characters are only chr(13) instead of chr(10),chr(13) This is why you have this behaviour. Ipconfig (under win 2000 ) is an other one.

You have to chop - rip - hack (!) every whitespace character at the start and end of every line, before you can use these lines.

I do not know how to do it with kixtart but within Perl I use the following :

s/^\s*(.*)\s*$/\1/;

Top
#62555 - 2002-01-31 02:54 AM Re: Redirecting command output...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
In kixtart, i would tend to code this difficult problem like this:

"@#%*&!!!"

nova, neat trick that non-delete folder thingy !

-Shawn

Top
#62556 - 2002-02-01 01:22 PM Re: Redirecting command output...
Sluice Offline
Fresh Scripter

Registered: 2001-11-13
Posts: 19
Loc: Romsey, England
You might like to look at COM objects to get the info you need, e.g.
$o_network = CreateObject("Wscript.Network")
$drivelist = $o_network.EnumNetworkDrives
;$drivelist is a collection i.e. an array that associates pairs of items - network drive local names (e.g. "j:") and their associated UNC names. Even-numbered items in the collection represent local names of logical drives. Odd-numbered items represent the associated UNC share names. The first item in the collection is at index zero (0).

$No_of_drives = $drivelist.count ;Count the no. of items in the drive list collection.
For $i= 0 to $No_of_drives -1 step 2
.....
Next

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.071 seconds in which 0.03 seconds were spent on a total of 12 queries. Zlib compression enabled.

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