RE: why does even statement with a value get stuffed into the output p
by S2FybCBQcm9zc2Vy » Sat, 26 Aug 2006 14:49:02 GMT
i don't have powershell on this computer so my syntax maybe off a little. But
i'll explain what is going on
anything that is returned from a function, or an expression gets put into
the pipeline.. so if you run
1..10
"hello"
, you'll get an array of 10 integers and a string.
being a shell, and wanting the user to be able to do thinks quickly they
didn't want to have to explicting do write-object...
but what is happening with your situation is that arraylist.add method (if
you look it up in the dotnet framework help) returns a value.. (the index in
the arraylist if i am not mistaken.. so powershell is adding this to the
pipeline.. you can CONSUME that result so that powershell doesn't add it to t
he pipeline in a number of ways
the first would be to put it into a variable
$local:dummy = $list.add(20)
however that is not so elegant.. there is an easier way and that it to
typecast the result as void, and i think this is the syntax
[void]$list.add(20)
also i don't think the return keyword is needed (but i could be wrong.. you
could write this function like this:
function foo
{
$list = new-object Collections.ArrayList
[void]$list.add(10)
[void]$list.add(20)
$list
}
hope that helps.
-------
Karl Prosser
maker of powershell analyzer
http://www.**--****.com/
Re: why does even statement with a value get stuffed into the output p
by Adam Milazzo » Sat, 26 Aug 2006 15:38:56 GMT
I realize this is how it is, but I don't think this is how it should be.
It seems that the majority of statements in a function are not intended
to be pushed into the pipeline. This means that the majority of
statements need to be redirected for the sake of the few (usually one)
that I actually want pushed into the pipeline.
Re: why does even statement with a value get stuffed into the output p
by Jouko Kynsijvi » Sat, 26 Aug 2006 20:46:40 GMT
There was a long discussion about this during the earlier betas. If i
remember correctly one of the suggestions was to use two keywords, something
like "function" and "scriptlet" etc. where former would not automatically
emit anything to the pipeline, and latter would just like function does now.
Since PS v1 is so close of beeing done, i think we'll have to live with the
current situation.
One way to easily discard any pipeline output without adding [void] etc to
every line producing unwanted output is to use something like this:
function foo {
$list = new-object Collections.ArrayList
&{
$list.add(10)
$list.add(20)
} | out-null
$list
}
Re: why does even statement with a value get stuffed into the output p
by Jeffrey Snover [MSFT] » Mon, 28 Aug 2006 04:56:24 GMT
A few of us where actually brainstorming just such a concept a few weeks
ago. There are pros and cons to the idea but please file a feature request
for this.
BTW - you might ask, "if you where thinking about doing it, why do I need to
file a feature request?". The answer is that we put potential features into
different buckets depending upon where they came from. Features requested
from users are (as a general rule) in a higher priority bucket.
--
Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Microsoft Corporation
This posting is provided "AS IS" with no warranties, no confers rights.
Visit the Windows PowerShell Team blog at:
http://www.**--****.com/
Visit the Windows PowerShell ScriptCenter at:
http://www.**--****.com/
Re: why does even statement with a value get stuffed into the output p
by Adam Milazzo » Mon, 28 Aug 2006 18:07:04 GMT
Re: why does even statement with a value get stuffed into the output p
by Karl Prosser » Thu, 31 Aug 2006 13:44:48 GMT
maybe a way to do with, would be a keyword with a scope, and everything
within that scope gets consumed (not returned, or put into the pipeline)
unless explicitly told to?
I choose the void keyword just an example, but beign a keyword it would be
included in base documentation, and peoples books etc.. and their is
consistency with the typecast [void]
what do you think
i.e
function foo
{
void {
$list = new-object Collections.ArrayList
$list.add(10)
$list.add(20)
return $list
}
}
Re: why does even statement with a value get stuffed into the output p
by Adam Milazzo » Fri, 01 Sep 2006 15:10:04 GMT
Perhaps this could be done as a "void" function that takes a script block...
function void([scriptblock]$block)
{
&$block | out-null
}
function foo
{
$local:list = new-object Collections.ArrayList
void {
$list.add(10)
$list.add(20)
}
return $list
}
This works, but it's not much of an improvement over:
function foo
{
$local:list = new-object Collections.ArrayList
$list.add(10) | out-null
$list.add(20) | out-null
return $list
}
or
function foo
{
$local:list = new-object Collections.ArrayList
($list.add(10); $list.add(20)) | out-null
return $list
}
But it's a neat idea. :-)
Re: why does even statement with a value get stuffed into the output p
by Jeffrey Snover [MSFT] » Fri, 01 Sep 2006 21:45:59 GMT
> function void([scriptblock]$block)
That IS a neat idea.
--
Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Microsoft Corporation
This posting is provided "AS IS" with no warranties, no confers rights.
Visit the Windows PowerShell Team blog at:
http://www.**--****.com/
Visit the Windows PowerShell ScriptCenter at:
http://www.**--****.com/
Similar Threads:
1.why does even statement with a value get stuffed into the output pipeline?
Consider this:
function foo
{
$list = new-object Collections.ArrayList
$list.add(10)
$list.add(20)
return $list
}
% foo
0
1
10
20
% foo | measure-object
Count: 3
...
It's actually returning an array of 3 objects. The first is the return
value of $list.add(10) (which is 0). The second is the return value of
$list.add(20) (which is 1). The third is the ArrayList object itself.
This is really annoying! Not to mention very unintuitive. In my opinion,
you should be required to use write-object to put things into the
pipeline, with the exception of "return <expression>", which would be
equivalent to "<expression> | write-object; return".
2.CAML statement to filter by two field values
Ok, I have a list that has two columns, say "ColumnOne" and
"ColumnTwo". I set up the following SPQuery.Query
"<Where><And><Eq><FieldRef Name='ColumnOne'/><Value Type='Text'>" +
valueOne + "</Value></Eq><Eq><FieldRef Name='ColumnTwo'/><Value
Type='Text'>" + valueTwo + "</Value></Eq></And></Where>"
I thought that the above query would only return items where both
fields match, i.e. ColumnOne = valueOne AND ColumnTwo = valueTwo, but
this is not the case... It returns results if either of the values
match.
What am I missing?
For more details on what I am doing.. The list might look like:
ColumnOne ColumnTwo
red john
red bob
blue john
etc...
What I want to be able to do is see if there is an item where ColumnOne
= red AND ColumnTwo = john. I am adding the items dynamically and do
not want to create duplicates....
3.Empty output oddity in conjunction with foreach statement
4.values for Windows version (dwMajorVersion, wServicePackMajor stuff)
i am working with these,
dwMajorVersion
dwMinorVersion
dwBuildNumber
dwPlatformId
wServicePackMajor
wServicePackMinor
1) So, dwMinorVersion (1) could only be Windows XP and dwMajorVersion
(6) could only be Windows Vista or Windows Server
2008?
2) So, if I had dwMinorVersion (1) and wServicePackMajor (1) that
could only be Windows XP SP1?
3) So, if I had dwMinorVersion (1) and wServicePackMajor (2) that
could only be Windows XP SP2?
4) Would dwMajorVersion (6) and wServicePackMajor (1) be possible?
Thank you. I am hoping these scattered questions will help me
understand this.
Crystal
5.Experiencing long pauses doing any internet stuff
Hello.
Windows XP Pro, SP2, IE 6.0 Mcafee Security Suite with all latest
windows/office/software updates, service packs and patches.
Whenever i try to do anything involving internet, i get these long
pauses(about a minute or two) between web sites or internet activity.
I tried most of the malware/virus fixes suggested in this forum.
I have this one program called Magic Mail Monitor. It shows me what my
emails are on the mail servers. When i start it, it takes an inordinate
amount of time to get all of the emails. It spends a lot of time saying
"Sending TOP Request". It takes a good 2 to 4 minutes for it to get all of
the emails.
I have MMM running on other computers on the same network and when i start
it, BAM! the emails popup instantly. That leads me to believe that it is
something with just this one computer.
It really makes me mad because this computer has the fastest megahertz
rating of all the computers on our network and it's the newest. It should
be fast. It doesn't seem to have that problem when running local software.
Does anybody have any idea of what i can do to eliminate those long pauses?
I tried just about everything.
Any help would be gratefully appreciated.
Thanks,
Tony
6. IE doing weird stuff
7. MS Word & MS Excell doing weird stuff
8. printer doing odd stuff