#199868 - 2010-09-14 07:10 PM
Redirectoutput
|
Tesdall
Getting the hang of it
Registered: 2009-10-02
Posts: 78
Loc: USA
|
Im trying to pipe informaton out to a text file and have it working in a BAT file. BUt im trying to convert it to a KIX script. Please let me know what im doing wrong.
Break on
DIM $server
Dim $settings
DIm $CD
$Server = server1
$Settings = server2
$OS = @PRODUCTTYPE
IF $OS = 'Windows XP Professional'
? "Change CD-ROM Drive Letter"
shell "diskpart.exe /s \\" + $Settings + "\it\newcomputer\Driveletter\chkdisk.txt"
? "Enter Volume Number for CDROM: "
Gets $CD
IF REDIRECTOUTPUT("\\" + $Settings + "\it\newcomputer\driveletter\chgdisk.txt",1) = 0
? "select Volume $CD"
? "assign letter Q noerr"
ENDIF
shell "diskpart.exe /s \\" + $Settings + "\it\newcomputer\Driveletter\chgdisk.txt"
Batch file
Echo Change CD-ROM Drive Letter
diskpart.exe /s "\\server2\it\tesdall\driveletter\chkdisk.txt"
set /p number= Enter Volume Number for CDROM:
Echo select disk 1 > "\\server2\it\newcomputer\driveletter\chgdisk.txt"
Echo select Volume %number% >> "\\usserve2\it\newcomputer\driveletter\chgdisk.txt"
Echo assign letter Q noerr>> "\\server2\it\newcomputer\driveletter\chgdisk.txt"
diskpart.exe /s "\\server2\it\newcomputer\driveletter\chgdisk.txt"
If i look in the chgdisk.txt file it shows things from farther down in the script, which is weird to me. Since, i though it would be stopping at the Endif.
_________________________
Where ever you go, there you are.
|
Top
|
|
|
|
#199869 - 2010-09-14 08:03 PM
Re: Redirectoutput
[Re: Tesdall]
|
Tesdall
Getting the hang of it
Registered: 2009-10-02
Posts: 78
Loc: USA
|
Bahhhh apparently that command doesn't do what i think it should do. So i changed my script. Everything appears to work now.
Here is the script that works (for me)
Break on
DIM $server
Dim $settings
DIm $CD
Dim $outfile
DIM $Writeline
$Server = server1
$Settings = server2
$OS = @PRODUCTTYPE
$OutFile = ('\\$Settings\it\newcomputer\driveletter\chgdisk.txt')
; Test open the output file
If Open( 2 , $OutFile, 5) <> 0
'Failed to open ' $OutFile ' - aborting!' ?
Exit 1
EndIf
IF $OS = 'Windows XP Professional'
? "Change CD-ROM Drive Letter"
shell "diskpart.exe /s \\" + $Settings + "\it\newcomputer\Driveletter\chkdisk.txt"
? "Enter Volume Number for CDROM: "
Gets $CD
$Writeline = Writeline(2, "Select Volume " + $CD + @CRLF + "Assign Letter Q noerr")
shell "diskpart.exe /s \\" + $Settings + "\it\newcomputer\Driveletter\chgdisk.txt"
$Writeline = close(2)
DEL '\\$settings\it\newcomputer\Driveletter\chgdisk.txt'
I should add this is a going to be a very large script. That is the reason it doesn't have the ELSE, endif and exit stuff at the bottom.
Hope this helps someone else.
_________________________
Where ever you go, there you are.
|
Top
|
|
|
|
#199870 - 2010-09-14 08:05 PM
Re: Redirectoutput
[Re: Tesdall]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Couple of things I see right away..
You aren't clearing the file, so every time you run the script, it will keep appending to the output file. Start by deleting the output file before the first RedirectOutput command. Your BAT file does clear the file, as it starts with ">" and continues with ">>".
Second, you aren't closing the redirection. Before the EndIf, add $ = RedirectOutput('') to terminate the redirection. Kix will continue to append all output to the file until you close it.
Finally, putting "?" at the start of a line is usually a matter of preference, but there are times it can bite you. Unlike BASIC, it is not a shortcut for the PRINT statement, but actually a shortcut to @CRLF. This character sequence naturally comes at the end of lines, not at the beginning. When doing file redirection, it causes your files to begin with a blank line and end without a CR/LF sequence. This can affect certain types of input files, especially those used as command input to other appls (ie: diskpart). Not saying it IS a problem, but it COULD become one if you aren't careful.
I rarely use "?" anymore, and always place it or @CRLF at the end of lines for this reason.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#199872 - 2010-09-14 08:36 PM
Re: Redirectoutput
[Re: Glenn Barnas]
|
Tesdall
Getting the hang of it
Registered: 2009-10-02
Posts: 78
Loc: USA
|
Im glad i could help. I am using the Manual to look up the commands and a lot of them dont have the "close command" for that command.
_________________________
Where ever you go, there you are.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|