#79484 - 2003-02-06 05:07 AM
Quoting Strings ??
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
|
There was a discussion about quoting strings - I can't find it right now - and I came across something tonight that may merit further discussion...
If I say: code:
$X = "first" ? "X=$X, Y=$Y" ?
I get "X=First, Y=$Y" - which I would kind of expect, since $Y is undeclared and inside of quotes. However, if I rewrite it as: code:
$X = "first" ? "X=$X, Y=" + $Y ?
I would expect the interpreter to recognize $Y as an uninitialized variable and output Null, but it outputs "$Y" again.
In this example, it isn't a big deal, but I have a few scripts that I was troubleshooting tonight where I execute a command via the Shell statement. I wanted to optionally write the results to a log file. I tried code:
If $OPTION = "-l" $LOG = "2>&1>> C:\TEMP\my.log" EndIf $CMD = "%COMSPEC% /c someprog.exe $LOG" shell $CMD
I expected that if $LOG was undefined, it would be NULL and the command output would appear as expected. If $LOG was defined, it would receive the results via the redirection. However, when $LOG is undefined, the command complains that "$LOG" is an unknown parameter.
Of course, this is easily fixed by first declaring $LOG to be null. Maybe there should be consideration for a defined "print" command that would treat all "$XXX" format strings as vars, initialized or not. ???
Glenn
PS - yes, I know that good coding requires that vars be declared, but that's why I script
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#79490 - 2003-02-07 03:41 AM
Re: Quoting Strings ??
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
|
What the ? ?
I was working with a rather complex script. It builds a command line to install a package of hotfixes as defined in an input file. The script reads the INI-format file and gets a list of hotfixes to apply. It then looks for each hotfix section to see if there are exceptions, different parameters, etc. before executing the hotfix file. It completes the process by running QCHAIN.exe. This has been working fine.
I decided to add some logging, since when we have our third-shift operations staff apply the hotfix package, the information scrolls by so fast they can't tell if it worked or not (they're "general" operators with Mainframe, Unix and NT skills - not NT admins.)
I'm not at work, so I'll pseudo-code - it works soft of like this: code:
if $OPTION = "-l" $LOG = " 2>&1>> LogFile.txt" EndIf
some other code...
$HFIX = "123456i.exe" ; read fom file $PARM = "-z" $CMD = "%COMSPEC% /c $HFIX $PARM" + $LOG ? "Executing $CMD" ? shell $CMD
At this time, when the shell command executes, it fails (unless I've passed the -l and defined the $LOG var) because the $CMD ends in "$LOG"
I fixed it by declaring $LOG="" at the beginning of the script, but I started doing the simple tests I illustrated before I posted the message. Now, at home (v4.12), it works the way you say (and the way I wanted it to!).
I'll review it again when I return to the office on Monday, but for now, I'm speechless.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#79498 - 2003-02-18 09:33 AM
Re: Quoting Strings ??
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: yes, you can use explicit. just do: redim preserve $myCMDlineVar
Ooerr. Works like a charm.
|
|
Top
|
|
|
|
Moderator: ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|