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 - Terminate Script Execution?

Reply
 
Old 10-11-2006   #1 (permalink)
MKielman


 
 

Terminate Script Execution?

I am trying to use ctrl+c to terminate a script but nothing happens. So
far I have only been able to close the command shell in order to get a
script to stop executing.

My System SpecsSystem Spec
Old 10-11-2006   #2 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Terminate Script Execution?

I've had similar issues with poorly-behaved objects. What's it hanging on?
There may be a way to work around this with the specific object.

"MKielman" <mkielman@newsgroups.nospam> wrote in message
news:OiIrXJU7GHA.1252@TK2MSFTNGP04.phx.gbl...
>I am trying to use ctrl+c to terminate a script but nothing happens. So far
>I have only been able to close the command shell in order to get a script
>to stop executing.



My System SpecsSystem Spec
Old 10-11-2006   #3 (permalink)
James Truher


 
 

Re: Terminate Script Execution?

it depends on what your script is doing, specifically, if you're in the
middle of a .NET Method call, CTRL-C won't take effect until the next script
line. Can you be more specific about what you're trying to do?

--
--
James Truher [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"MKielman" <mkielman@newsgroups.nospam> wrote in message
news:OiIrXJU7GHA.1252@TK2MSFTNGP04.phx.gbl...
>I am trying to use ctrl+c to terminate a script but nothing happens. So far
>I have only been able to close the command shell in order to get a script
>to stop executing.



My System SpecsSystem Spec
Old 10-11-2006   #4 (permalink)
MKielman


 
 

Re: Terminate Script Execution?

My script uses the get-wmiobject using the Win32_QuickFixEngineering and
Win32_OperatingSystem classes. I am reading text file that has a list of
about 300 servers and I am querying those WMI objects for each server in
a foreach loop. When I encounter a problem and I want to stop the script
from executing nothing seems to work except for closing the shell which
is a pain.



James Truher wrote:
> it depends on what your script is doing, specifically, if you're in the
> middle of a .NET Method call, CTRL-C won't take effect until the next script
> line. Can you be more specific about what you're trying to do?
>

My System SpecsSystem Spec
Old 10-11-2006   #5 (permalink)
MKielman


 
 

Re: Terminate Script Execution?

My script uses the get-wmiobject using the Win32_QuickFixEngineering and
Win32_OperatingSystem classes. I am reading text file that has a list of
about 300 servers and I am querying those WMI objects for each server in
a foreach loop. When I encounter a problem and I want to stop the script
from executing nothing seems to work except for closing the shell which
is a pain.

James Truher wrote:
> it depends on what your script is doing, specifically, if you're in the
> middle of a .NET Method call, CTRL-C won't take effect until the next script
> line. Can you be more specific about what you're trying to do?
>

My System SpecsSystem Spec
Old 10-11-2006   #6 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Terminate Script Execution?

Could you show your example code?

You might be timing out when attempting to connect to a system. To determine
exactly where the problem crops up, you might also include some verbose
statements within the script so you know approximately where you are in the
code when you can't break out.


"MKielman" <mkielman@newsgroups.nospam> wrote in message
news:e0pgIrW7GHA.3836@TK2MSFTNGP02.phx.gbl...
> My script uses the get-wmiobject using the Win32_QuickFixEngineering and
> Win32_OperatingSystem classes. I am reading text file that has a list of
> about 300 servers and I am querying those WMI objects for each server in a
> foreach loop. When I encounter a problem and I want to stop the script
> from executing nothing seems to work except for closing the shell which is
> a pain.
>
> James Truher wrote:
>> it depends on what your script is doing, specifically, if you're in the
>> middle of a .NET Method call, CTRL-C won't take effect until the next
>> script line. Can you be more specific about what you're trying to do?
>>



My System SpecsSystem Spec
Old 10-11-2006   #7 (permalink)
MKielman


 
 

Re: Terminate Script Execution?

You are all missing the point. I simply want to terminate a script while
it is running no matter what it is doing. The script itself is not hung,
it just takes a long time to finish because it is reading a file and
performing a task using each line of input. Basically, I am sitting at
the shell and have run ./script.ps1. The script is running and printing
output to the screen but I want to stop it. On a Unix shell I can use
ctrl+c to cancel what the shell is currently running.



Alex K. Angelopoulos [MVP] wrote:
> Could you show your example code?
>
> You might be timing out when attempting to connect to a system. To determine
> exactly where the problem crops up, you might also include some verbose
> statements within the script so you know approximately where you are in the
> code when you can't break out.
>
>
> "MKielman" <mkielman@newsgroups.nospam> wrote in message
> news:e0pgIrW7GHA.3836@TK2MSFTNGP02.phx.gbl...
>> My script uses the get-wmiobject using the Win32_QuickFixEngineering and
>> Win32_OperatingSystem classes. I am reading text file that has a list of
>> about 300 servers and I am querying those WMI objects for each server in a
>> foreach loop. When I encounter a problem and I want to stop the script
>> from executing nothing seems to work except for closing the shell which is
>> a pain.
>>
>> James Truher wrote:
>>> it depends on what your script is doing, specifically, if you're in the
>>> middle of a .NET Method call, CTRL-C won't take effect until the next
>>> script line. Can you be more specific about what you're trying to do?
>>>

>
>

My System SpecsSystem Spec
Old 10-11-2006   #8 (permalink)
Roman Kuzmin


 
 

Re: Terminate Script Execution?

Can you terminate this script by ctrl-c?

1..1111 | %{$_; sleep 1}

--
Thanks,
Roman


My System SpecsSystem Spec
Old 10-11-2006   #9 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Terminate Script Execution?

"MKielman" <mkielman@newsgroups.nospam> wrote in message
news:u$QWouX7GHA.4064@TK2MSFTNGP03.phx.gbl...
> You are all missing the point. I simply want to terminate a script while
> it is running no matter what it is doing.


And since it doesn't "just work" when PS execution is tied to an external
process (such as wmiprvse.exe in this case), I was hoping to find out where
in the cycle the script is choking. That would give me some ideas about a
good bug report for this behavior and possibly point to an interim
workaround.

> ... The script itself is not hung,


Sounds like it would be more accurate to describe this as "PowerShell is not
immediately responsive to an attempt to break execution somewhere in the
script". I was under the impression that it was hanging because you said
that nothing worked - presumably meaning that control never, ever returned
to you, no matter how long you waited.

What I was really after was enough information to determine where this is
happening. If you think this is ugly and nasty compared to Unix process
handling, I have to agree with you.


My System SpecsSystem Spec
Old 10-12-2006   #10 (permalink)
Andrew Watt [MVP]


 
 

Re: Terminate Script Execution?

Hi,

Ctrl+Z sometimes works when Ctrl+C doesn't.

I am not entirely clear on why or when.

And I don't know if it works "no matter what" a script is doing.

Andrew Watt MVP

On Wed, 11 Oct 2006 14:24:34 -0700, MKielman
<mkielman@newsgroups.nospam> wrote:

>You are all missing the point. I simply want to terminate a script while
>it is running no matter what it is doing. The script itself is not hung,
>it just takes a long time to finish because it is reading a file and
>performing a task using each line of input. Basically, I am sitting at
>the shell and have run ./script.ps1. The script is running and printing
>output to the screen but I want to stop it. On a Unix shell I can use
>ctrl+c to cancel what the shell is currently running.
>
>
>
>Alex K. Angelopoulos [MVP] wrote:
>> Could you show your example code?
>>
>> You might be timing out when attempting to connect to a system. To determine
>> exactly where the problem crops up, you might also include some verbose
>> statements within the script so you know approximately where you are in the
>> code when you can't break out.
>>
>>
>> "MKielman" <mkielman@newsgroups.nospam> wrote in message
>> news:e0pgIrW7GHA.3836@TK2MSFTNGP02.phx.gbl...
>>> My script uses the get-wmiobject using the Win32_QuickFixEngineering and
>>> Win32_OperatingSystem classes. I am reading text file that has a list of
>>> about 300 servers and I am querying those WMI objects for each server in a
>>> foreach loop. When I encounter a problem and I want to stop the script
>>> from executing nothing seems to work except for closing the shell which is
>>> a pain.
>>>
>>> James Truher wrote:
>>>> it depends on what your script is doing, specifically, if you're in the
>>>> middle of a .NET Method call, CTRL-C won't take effect until the next
>>>> script line. Can you be more specific about what you're trying to do?
>>>>

>>
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Conditional execution of script for logged-on user VB Script
Script Execution Over Network VB Script
Re: Can't terminate processes Vista performance & maintenance
Retaining variables after script execution PowerShell
"background" script execution PowerShell


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