Page 1 of 1 1
Topic Options
#19998 - 2002-04-16 06:26 PM problem using shell to echo a string
Jtel Offline
Fresh Scripter

Registered: 2002-04-13
Posts: 41
I am trying to use the Shell function to echo a string to another file to create a batch file on the fly. This works fine except for this particular string because the string itself contains ">" to output to another file. Here's what I'm trying to do:
shell '%comspec% /c echo type c:\report.txt>c:\%computername%.txt>'+c:\test.bat

The desired result would be for test.bat to contain a line with:
type c:\report.txt>c:\%computername%.txt
Unfortunately, the > in the middle of the string causes a problem and I end up with only:
type c:\report.txt

any suggestions?

Top
#19999 - 2002-04-16 06:37 PM Re: problem using shell to echo a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Instead of SHELLing out do it all from KiX.

code:
If Exist($WorkDir + "\vpcur.lst") Del $WorkDir + "\vpcur.lst" EndIf
$FTPScript = $WorkDir + "\CEGetCurrent.txt"
$ShellCMD ="ftp -s:" + $FTPScript
If Exist($FTPScript) Del '$FTPScript' Endif
If RedirectOutput($FTPScript) = 0
"open ftp.symantec.com" ?
"anonymous" ?
"les_ligetfalvy@@abicon.com" ?
"cd public/english_us_canada/antivirus_definitions/norton_antivirus/static" ?
"lcd " + $WorkDir ?
"bin" ?
"hash" ?
"prompt" ?
"get vpcur.lst" ?
"quit" ?
$rc = RedirectOutput("")
Else
$Error ="Failed to create " + $FTPScript
GoTo ExitError
Endif
Shell '$ShellCMD'

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#20000 - 2002-04-16 09:58 PM Re: problem using shell to echo a string
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
The redirectoutput method seems easy enough.

A simple:
...
IF REDIRECTOUTPUT("c:\test.bat") = 0
? "type c:\report.txt>c:\%computername%.txt"
?
ENDIF
...
should work.. maybe too obvious. Alternately, you can open the file and add a line:
...
IF OPEN (1,"c:\test.bat",4) = 0
$ok = WRITELINE (1,"type c:\report.txt>c:\%computername%.txt" + @CRLF)
$ok = CLOSE(1)
ENDIF
....
If you're using an older version of kix, then don't use + @CLRF but + chr(13) + chr(10) to add a carriage return and line feed.

This would be another method that should also work.

Brian

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 1452 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.026 seconds in which 0.013 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