meissnersd
meissnersd

Reputation: 1312

Powershell ISE appears to hang with interactive commands.

I've just downloaded Powershell 2.0 and I'm using the ISE. In general I really like it but I am looking for a workaround on a gotcha. There are a lot of legacy commands which are interactive. For example xcopy will prompt the user by default if it is told to overwrite a file.

In the Powershell ISE this appears to hang

mkdir c:\tmp                                                                                       
cd c:\tmp                                                                                          
dir > tmp.txt                                                                                      
mkdir sub                                                                                          
xcopy .\tmp.txt sub # fine
xcopy .\tmp.txt sub # "hang" while it waits for a user response.

The second xcopy is prompting the user for permission to overwrite C:\tmp\sub\tmp.txt, but the prompt is not displayed in the ISE output window. I can run this fine from cmd.exe but then what use is ISE? How do I know when I need which one?

Upvotes: 7

Views: 2388

Answers (2)

Shay Levy
Shay Levy

Reputation: 126722

In a nutshell, Interactive console applications are not supported in ISE (see link below). As a workaround, you can "prevent" copy-item from overwriting a file by checking first if the file exists using test-path.

http://blogs.msdn.com/powershell/archive/2009/02/04/console-application-non-support-in-the-ise.aspx

Upvotes: 6

Ken White
Ken White

Reputation: 125651

Why would you be using XCOPY from PowerShell ISE? Use Copy-Item instead:

Copy-Item -Path c:\tmp\tmp.txt -Destination c:\tmp\sub

It will overwrite any existing file without warning, unless the existing file is hidden, system, or read-only. If you want to overwrite those as well, you can add the -force parameter.

See the topic "Working with Files and Folders" in the PowerShell ISE help file for more info, or see all the commands at MSDN.

Upvotes: 1

Related Questions