Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Stderror redirect bug?

Reply
 
Old 05-10-2007   #1 (permalink)
Keith Hill [MVP]


 
 

Stderror redirect bug?

I think I might have found a bug. The following command (3rd line) properly
redirects the error stream to the file:

copy-item *.ps1 c:\temp
gci c:\temp\*.ps1 | %{$_.IsReadOnly = $true}
copy-item *.ps1 c:\temp 2>&1 > foo.txt

However if I now add -force, the error stream is no longer redirected to the
file:

copy-item *.ps1 c:\temp -force 2>&1 > foo.txt

That's got to be a bug right? Never mind the fact that -force doesn't
"force" the overwrite of a read-only file - grrr. BTW if you think
that -force should allow overwrites of readonly files (like it does with
UNIX cp -f), then vote on this issue at:

https://connect.microsoft.com/feedba...3448&SiteID=99

--
Keith



My System SpecsSystem Spec
Old 05-10-2007   #2 (permalink)
Gerd Schneider


 
 

RE: Stderror redirect bug?

Keith,

I played around a little bit with your example and found some more
surprising behavior. What about this:

C:>'abc' > foo.dat
C:>type foo.dat
abc
C:>'xyz' > foo.new
C:>type foo.new
xyz
C:>(gi foo.dat).isreadonly=$true
C:>(gi foo.dat).isreadonly
True
C:>copy foo.new foo.dat -force
Copy-Item : The file 'C:\Documents and Settings\schneger\Local
Settings\Temp\foo.dat' already exists.
At line:1 char:5
+ copy <<<< foo.new foo.dat -force
C:>copy -force foo.new foo.dat
C:>type foo.dat
xyz
C:>

-force is very well able to overwrite r/o files - depending on the placement
in the copy commandline. I agree, this looks like a serious bug in
commandline parsing.

Gerd


"Keith Hill [MVP]" wrote:

> I think I might have found a bug. The following command (3rd line) properly
> redirects the error stream to the file:
>
> copy-item *.ps1 c:\temp
> gci c:\temp\*.ps1 | %{$_.IsReadOnly = $true}
> copy-item *.ps1 c:\temp 2>&1 > foo.txt
>
> However if I now add -force, the error stream is no longer redirected to the
> file:
>
> copy-item *.ps1 c:\temp -force 2>&1 > foo.txt
>
> That's got to be a bug right? Never mind the fact that -force doesn't
> "force" the overwrite of a read-only file - grrr. BTW if you think
> that -force should allow overwrites of readonly files (like it does with
> UNIX cp -f), then vote on this issue at:
>
> https://connect.microsoft.com/feedba...3448&SiteID=99
>
> --
> Keith
>
>
>

My System SpecsSystem Spec
Old 05-10-2007   #3 (permalink)
IJuan


 
 

RE: Stderror redirect bug?

If you read the link the Keith gave it states the the first time you run the
copy with the force switch and clears the readonly flag but doesn't actually
do the copy. So the second time you run the copy you don't even need the
force switch and it will copy.

Copy-Item definitely needs to be fixed in the way it handles files that
already exist.


-= IJuan =-

"Gerd Schneider" wrote:

> Keith,
>
> I played around a little bit with your example and found some more
> surprising behavior. What about this:
>
> C:>'abc' > foo.dat
> C:>type foo.dat
> abc
> C:>'xyz' > foo.new
> C:>type foo.new
> xyz
> C:>(gi foo.dat).isreadonly=$true
> C:>(gi foo.dat).isreadonly
> True
> C:>copy foo.new foo.dat -force
> Copy-Item : The file 'C:\Documents and Settings\schneger\Local
> Settings\Temp\foo.dat' already exists.
> At line:1 char:5
> + copy <<<< foo.new foo.dat -force
> C:>copy -force foo.new foo.dat
> C:>type foo.dat
> xyz
> C:>
>
> -force is very well able to overwrite r/o files - depending on the placement
> in the copy commandline. I agree, this looks like a serious bug in
> commandline parsing.
>
> Gerd
>
>
> "Keith Hill [MVP]" wrote:
>
> > I think I might have found a bug. The following command (3rd line) properly
> > redirects the error stream to the file:
> >
> > copy-item *.ps1 c:\temp
> > gci c:\temp\*.ps1 | %{$_.IsReadOnly = $true}
> > copy-item *.ps1 c:\temp 2>&1 > foo.txt
> >
> > However if I now add -force, the error stream is no longer redirected to the
> > file:
> >
> > copy-item *.ps1 c:\temp -force 2>&1 > foo.txt
> >
> > That's got to be a bug right? Never mind the fact that -force doesn't
> > "force" the overwrite of a read-only file - grrr. BTW if you think
> > that -force should allow overwrites of readonly files (like it does with
> > UNIX cp -f), then vote on this issue at:
> >
> > https://connect.microsoft.com/feedba...3448&SiteID=99
> >
> > --
> > Keith
> >
> >
> >

My System SpecsSystem Spec
Old 05-10-2007   #4 (permalink)
Gerd Schneider


 
 

RE: Stderror redirect bug?

I tried that. You're right.

"IJuan" wrote:

> If you read the link the Keith gave it states the the first time you run the
> copy with the force switch and clears the readonly flag but doesn't actually
> do the copy. So the second time you run the copy you don't even need the
> force switch and it will copy.
>
> Copy-Item definitely needs to be fixed in the way it handles files that
> already exist.
>
>
> -= IJuan =-
>
> "Gerd Schneider" wrote:
>
> > Keith,
> >
> > I played around a little bit with your example and found some more
> > surprising behavior. What about this:
> >
> > C:>'abc' > foo.dat
> > C:>type foo.dat
> > abc
> > C:>'xyz' > foo.new
> > C:>type foo.new
> > xyz
> > C:>(gi foo.dat).isreadonly=$true
> > C:>(gi foo.dat).isreadonly
> > True
> > C:>copy foo.new foo.dat -force
> > Copy-Item : The file 'C:\Documents and Settings\schneger\Local
> > Settings\Temp\foo.dat' already exists.
> > At line:1 char:5
> > + copy <<<< foo.new foo.dat -force
> > C:>copy -force foo.new foo.dat
> > C:>type foo.dat
> > xyz
> > C:>
> >
> > -force is very well able to overwrite r/o files - depending on the placement
> > in the copy commandline. I agree, this looks like a serious bug in
> > commandline parsing.
> >
> > Gerd
> >
> >
> > "Keith Hill [MVP]" wrote:
> >
> > > I think I might have found a bug. The following command (3rd line) properly
> > > redirects the error stream to the file:
> > >
> > > copy-item *.ps1 c:\temp
> > > gci c:\temp\*.ps1 | %{$_.IsReadOnly = $true}
> > > copy-item *.ps1 c:\temp 2>&1 > foo.txt
> > >
> > > However if I now add -force, the error stream is no longer redirected to the
> > > file:
> > >
> > > copy-item *.ps1 c:\temp -force 2>&1 > foo.txt
> > >
> > > That's got to be a bug right? Never mind the fact that -force doesn't
> > > "force" the overwrite of a read-only file - grrr. BTW if you think
> > > that -force should allow overwrites of readonly files (like it does with
> > > UNIX cp -f), then vote on this issue at:
> > >
> > > https://connect.microsoft.com/feedba...3448&SiteID=99
> > >
> > > --
> > > Keith
> > >
> > >
> > >

My System SpecsSystem Spec
Old 05-12-2007   #5 (permalink)
Keith Hill [MVP]


 
 

Re: Stderror redirect bug?

"Keith Hill [MVP]" <r_keith_hill@no.spam.thank.u.hotmail.com> wrote in
message news:uKeIzhxkHHA.1776@TK2MSFTNGP05.phx.gbl...
>I think I might have found a bug. The following command (3rd line)
>properly redirects the error stream to the file:
>
> copy-item *.ps1 c:\temp
> gci c:\temp\*.ps1 | %{$_.IsReadOnly = $true}
> copy-item *.ps1 c:\temp 2>&1 > foo.txt
>
> However if I now add -force, the error stream is no longer redirected to
> the file:
>
> copy-item *.ps1 c:\temp -force 2>&1 > foo.txt


I submitted this defect. If you can validate it, please vote on it here:

https://connect.microsoft.com/feedba...6933&SiteID=99

--
Keith


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Redirect all output PowerShell
reading stderror stream VB Script
IE redirect problem Vista General
URL Redirect Problem Vista General
Redirect of (my Documents) Vista file management


Vista Forums 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 Ltd

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