Page 1 of 1 1
Topic Options
#150536 - 2005-10-25 03:31 PM Helpful Hint(?)
tsmith Offline
Fresh Scripter

Registered: 2005-10-19
Posts: 27
You say you want to 'shell' out with a long line of code, but Kixtart won't allow it? Say, something like this:

GO "C:"
CD "\"
Shell "%COMSPEC% /e:1024 /c DIR /s *.mp? > Y:DSI_" + @YEAR@MONTHNO + "_" + @WKSTA + ".txt"

This will *not* work. (Well, not for *me* anyway.) So you have to build it in pieces. Try this:

Dim $ShellStr
$ShellStr = ""
$ShellStr = "%COMSPEC% /e:1024 /c DIR /s *.mp? > Y:DSI_" + @YEAR
$ShellStr = $ShellStr + @MONTHNO
$ShellStr = $ShellStr + "_" + @WKSTA + ".txt"
GO "C:"
CD "\"
SHELL $ShellStr

This *does* work.

(I just thought this might save someone else a few hours of head banging against that proverbial brick wall. )

Tom

Top
#150537 - 2005-10-25 03:46 PM Re: Helpful Hint(?)
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I think the reason it didn't work is because @year@monthno should be @year + @monthno.

But nonetheless, building out shell statements is a good idea, imho. Another good idea is to run it at the command prompt first, ensure that it works like you want it to and then add it to your script.

Top
#150538 - 2005-10-25 03:53 PM Re: Helpful Hint(?)
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yeah, like maciep says in the first example you do @YEAR@MONTHNO and it does not work.
In the second example you do @YEAR + @MONTHNO and it works.
What if you put the + between the @YEAR and the @MONTHNO in the first example does it work then?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#150539 - 2005-10-25 05:20 PM Re: Helpful Hint(?)
tsmith Offline
Fresh Scripter

Registered: 2005-10-19
Posts: 27
Well now... Guess what? Placing a '+' between them *does* work. So...

This does: @YEAR + @MONTHNO

This doesn't: @YEAR@MONTHNO

Hmmm... In those words of that famous Cuban Band Leader, Ricky Ricardo...

"Lucy, you gotta lotta splainin to do!"

Seriously, could I impose upon someone to explain the difference between this (which works):

If Not Exist ("Y:CompInfo_@YEAR@MONTHNO.txt")

and this? (which doesn't work):

Shell "%COMSPEC% /e:1024 /c DIR /s *.mp? > Y:DSI_" + @YEAR@MONTHNO + "_" + @WKSTA + ".txt"

I'm assuming that I thought if one worked, that the other should too, which is why I hadn't tried placing a '+' between them myself.

Thanks,

Tom

Top
#150540 - 2005-10-25 06:21 PM Re: Helpful Hint(?)
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
In a nutshell, it's the way KiX interprets the command line.

with
"string" + @MACRO1@MACRO2 + "String", Kix ends the command with @Macro1, and probably prints Macro2 and the lines that follow. If you had the macros in the string, it would work. Outside the string, if you did
? "sting" @M1@M2 "string"
it would work, but when you're building a parameter list for a command or function, you need to explicitly contatenate (+) each component. That's why it works with the "+" and not without it.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#150541 - 2005-10-26 11:34 AM Re: Helpful Hint(?)
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I'll elaborate on Glenn's explanation a little.

The issue is one of expressions. KiXtart is a fairly free format language, which allows you to do things like place multiple commands or expressions on a single line.

For example, the following three scripts are all equivalent:
Code:
$a=1
$b=2


Code:
$a
=
1
$b
=
2


Code:
$a=1$b=2



You can see in the second example that we didn't even need a space between the two expressions - the interpreter knows when it sees the "$" character that the previous expression has ended.

With a very few exceptions (such as a comment), KiXtart has no understanding of a "line" of script.

Consider this simple example:
Code:
"Your login is "@USERID@CRLF


This is actually three completely seperate expressions which have nothing to do with each other. You just happened to put them on one line. Each expression is evaluated and the output sent to the console before the interpreter moves on to the next one.

You could code this as a single expression:
Code:
"Your login is "+@USERID+@CRLF


Now, as each sub-expression is evaluated it is kept on the internal data stack and the operator (+) is applied. The result is a single expression or value which is output to the console in one pass.

Another way of making this a single expression is to include the variables in the quotes, however this has it's own problems and you are strongly advised to avoid "VarsInStrings".

The difference is not just a matter of coding style as you've already seen.

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 1283 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.059 seconds in which 0.027 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