Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Only the first command is is formatted

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-01-2007   #1 (permalink)
John Vottero
Guest


 

Only the first command is is formatted

I'm working on a project that hosts PowerShell scripts and I ran into a
problem that I haven't been able to figure out. Only the first command in a
script is formatted as expected. After that, the output is formatted as if
there were no format data files (*.format.ps1xml).

I found that the Host03 sample that ships with the SDK illustrates this
problem. If you build and run the Host03 sample and enter:

dir; get-process

you will see a directory listing formatted with one line per file and then
you will see a process listing but, each process is formatted like:

Id : 3184
Handles : 315
CPU : 1.923
Name : procname

If you enter:

get-process; dir

you will see a process listing formatted with one line per process and then
you see a directory listing but, each file appears like:

LastWriteTime : 1/1/2007 12:34 PM
Length: : 100
Name : Host03.pdb

Can anyone explain this? What's going on?

Also, if you type:

dir; dir

why do you only get one directory heading?




My System SpecsSystem Spec
Old 01-01-2007   #2 (permalink)
John Vottero
Guest


 

Re: Only the first command is is formatted

I just realized that you don't even have to use the Host03 sample to
illustrate this. You can just type:

dir; get-process

and

get-process; dir

at the PowerShell prompt. Why isn't the second command formatted?


My System SpecsSystem Spec
Old 01-01-2007   #3 (permalink)
Jeffrey Snover [MSFT]
Guest


 

Re: Only the first command is is formatted

try these:
dir |out-default; gps
gps | out-default; dir

What is happening is that you didn't specify a formatter so what happens is
that you generated a single stream of heterogenous objects and then the
SHELL sends that SINGLE stream gets sent to formatting and outputting. They
way format/outputing works is that the first object in the stream is used to
loopup format information. That information is then used to format the rest
of the stream. If it encounters an object that isn't part of that
formatting record, it does a FORMAT-list on it.

In this example, I fake up a heterogenous array of objects and emit them for
formatting to show how this is working. You can control when to start a NEW
formating stream by being explicit with your formatting (e.g. piping to
out-default)

PS> $x= (dir)[0],(gps)[0],(dir)[1],(gps)[1]
PS> $x


Directory: Microsoft.PowerShell.Core\FileSystem::C:\ps


Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 11/21/2006 2:33 PM jobs

Id : 6340
Handles : 232
CPU : 21.140625
Name : AcroRd32

d---- 11/21/2006 2:33 PM PhotoLibrary Binaries

Id : 3396
Handles : 73
CPU :
Name : alg

--
Jeffrey Snover [MSFT]
Windows PowerShell Architect
Microsoft Corporation
This posting is provided "AS IS" with no warranties, no confers rights.


My System SpecsSystem Spec
Old 01-02-2007   #4 (permalink)
John Vottero
Guest


 

Re: Only the first command is is formatted

Thanks, I understand what's going on now. It's not what I would expect,
when a script is being executed, I would expect the first line to be
completed before the second line is started. But, the more I think about
it, the more I like it.


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot e mail a picture because it is not formatted? aura10 Vista music pictures video 1 06-20-2008 03:17 AM
Help, please. DVD-RW thinks every disc needs to be formatted qbit General Discussion 4 05-31-2008 06:21 AM
Problems with a formatted drive Demons77 Vista performance & maintenance 1 11-15-2007 05:45 AM
formatted vista hd in rage and .... bigger brother Vista installation & setup 5 06-24-2007 10:23 AM
just formatted my PC and can't re-activate tingly Vista installation & setup 7 05-19-2007 07:18 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51