#62540 - 2002-01-30 11:47 AM
Redirecting command output...
|
mvdw
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
|
|
|
|
#62542 - 2002-01-30 01:29 PM
Re: Redirecting command output...
|
Will Hetrick
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
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 ? loopthat 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
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
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
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
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
|
|
|
|
#62550 - 2002-01-30 05:04 PM
Re: Redirecting command output...
|
mvdw
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
|
|
|
|
#62552 - 2002-01-30 06:04 PM
Re: Redirecting command output...
|
Richard H.
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
|
|
|
|
#62554 - 2002-01-31 02:16 AM
Re: Redirecting command output...
|
Anonymous
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
|
|
|
|
#62556 - 2002-02-01 01:22 PM
Re: Redirecting command output...
|
Sluice
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|