Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 535
meissnersd Avatar asked Nov 20 '09 20:11

meissnersd


People also ask

Is PowerShell ISE deprecated?

1. The PowerShell ISE is no longer in active feature development. As a shipping component of Windows, it continues to be officially supported for security and high-priority servicing fixes. We currently have no plans to remove the ISE from Windows.

What is difference between PowerShell and PowerShell ISE?

The principal difference between the two is convenience. PowerShell is a simpler and more straightforward scripting and execution environment, while the ISE provides more flexible and forgiving editing and execution features. PowerShell can be a good platform for simple tasks where actions are clear.

What does ISE stand for in PowerShell?

You can use the Windows PowerShell Integrated Scripting Environment (ISE) to create, run, and debug commands and scripts. The Windows PowerShell ISE consists of the menu bar, Windows PowerShell tabs, the toolbar, script tabs, a Script Pane, a Console Pane, a status bar, a text-size slider and context-sensitive Help.

How do I enable PowerShell ISE?

From the Start Menu. Click Start, type ISE, and then click Windows PowerShell ISE. From the Start menu, click Start, click All Programs, click Accessories, click the Windows PowerShell folder, and then click Windows PowerShell ISE.


2 Answers

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

like image 143
Shay Levy Avatar answered Sep 24 '22 21:09

Shay Levy


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.

like image 34
Ken White Avatar answered Sep 22 '22 21:09

Ken White