PowerShell ISE Ctrl+C/Break on java processes (maven)

First hello to all :)
Second the problem:
Each time I try to kill a java process ( by sending the command Ctrl+C) I see the message Stopping in the status bar, the console output is 'frozen' and nothing happens until the java process stops or I kill it from Task Manager. Is there an workaround
for this issue?
Thank you in advance,
Sergiu.
Best Regards.

Hi Sergiu,
As a workaround, May be you can try to trap the key Ctrl+C and start your script as a job.
start-job -scriptblock {. Pathofyourscript.ps1}, Then stop the job if CTRL+C is pressed.
[console]::TreatControlCAsInput = $true
while ($true)
Start-Sleep -s 30
if ([console]::KeyAvailable)
$key = [system.console]::readkey($true)
if (($key.modifiers -band [consolemodifiers]"control") -and
($key.key -eq "C"))
"Terminating..."
get-job | stop-job
break
For more detailed script, please check this thread:
Trapping CTRL+C in Powershell V2
I hope this helps.

Similar Messages

  • Powershell ISE – change indent/tab size + keep tabs

    Anyway to change indent/tab size in Powershell ISE?
    Something simple like in Visual studio IDE:
    Tab size 2
    Indent size 2
    Keep tabs

    Figured I'd share the changes I made to NoSimDash's above code. I actually wrote this not long after he posted his reply, but decided not to post it after I settled on taking the cheap, hacky timer route. (Originally I was looking to have the process triggered
    by an event when the user changed tabs)
    Anyways, over the last two years it's been pretty stable, so I thought I'd share on the off-chance that someone goes looking for this functionality again.
    $psISE.Options.ShowOutlining = $true
    $psISE.Options.ShowDefaultSnippets = $true
    $psISE.Options.ShowIntellisenseInScriptPane = $true
    $psISE.Options.ShowIntellisenseInConsolePane = $true
    Set-Variable -Option AllScope -Name OptionSetter -Value (&{
    $ClassName = 'IndentFixer'
    $Namespace = 'ISEHijack'
    Add-Type @"
    internal class _Option<TValue>
    public _Option(string key, TValue value)
    Key = key;
    Value = value;
    public Object[] Params { get { return new object[] { Key, Value }; } }
    public string Key { get; private set; }
    public TValue Value { get; private set; }
    internal static object[] Opt<TVal>(string key, TVal value)
    return new _Option<TVal>(key, value).Params;
    internal static readonly object[][] NewOpts = {
    Opt<bool>("Adornments/HighlightCurrentLine/Enable", false),
    Opt<int>("Tabs/TabSize", 4),
    Opt<int>("Tabs/IndentSize", 4),
    Opt<bool>("Tabs/ConvertTabsToSpaces", false),
    Opt<bool>("TextView/UseVirtualSpace", false),
    Opt<bool>("TextView/UseVisibleWhitespace", true)
    internal void SetOpts()
    foreach(object[] args in NewOpts) {
    Setter.Invoke(Options, args);
    public MethodInfo Setter { get; set; }
    public object Options { get; set; }
    public Dispatcher EditorDispatcher { get; set; }
    public List<Action> Actions { get; private set; }
    public ${ClassName}()
    Actions = new List<Action>();
    Actions.Add(SetOpts);
    public void Dispatch(Dispatcher dispatcher)
    DispatcherFrame frame = new DispatcherFrame();
    dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(ExitFrames), frame);
    Dispatcher.PushFrame(frame);
    private object ExitFrames(object f){
    DispatcherFrame frame = ((DispatcherFrame)f);
    // foreach(Action action in Actions) {
    // action.Invoke();
    // Actions.Clear();
    foreach(object[] args in NewOpts) {
    Setter.Invoke(Options, args);
    frame.Continue = false;
    return null;
    "@ -Name $ClassName `
    -NameSpace $Namespace `
    -UsingNamespace System.Windows.Forms,System.Windows.Threading,System.Reflection,Microsoft.VisualStudio.Text.EditorOptions.Implementation,System.Collections.Generic `
    -ReferencedAssemblies WindowsBase,System.Windows.Forms,Microsoft.PowerShell.Editor
    return `
    "${Namespace}.${ClassName}" |
    Add-Member -Type NoteProperty -Name Namespace -Value $Namespace -Passthru |
    Add-Member -Type NoteProperty -Name ClassName -Value $ClassName -Passthru
    [System.Reflection.BindingFlags] $NonPublicFlags = [System.Reflection.BindingFlags] 'NonPublic,Instance'
    filter Expand-Property
    PARAM(
    [Alias('Property')]
    [ValidateNotNullOrEmpty()]
    [Parameter(Mandatory, Position=0)]
    [String] $Name
    $_ | Select-Object -ExpandProperty $Name | Write-Output
    function Get-IsePrefs
    PARAM(
    [Parameter(Mandatory, Position=1)]
    [ValidateNotNullOrEmpty()]
    [string] $Key
    $oEditor = $psISE.CurrentFile.Editor
    $tEditor = $oEditor.GetType()
    $tEditor.GetProperty('EditorOperations', $NonPublicFlags).GetMethod.Invoke($oEditor, $null).Options | `
    Expand-Property GlobalOptions | `
    Expand-Property SupportedOptions | `
    Select-Object -Property Key,ValueType,DefaultValue | `
    Write-Output
    function Comment-Selection
    $output = ''
    $psISE.CurrentFile.Editor.SelectedText.Split("`n") | ForEach-Object -Process { $output += "# " + [string]$_ + "`n" }
    $psISE.CurrentFile.Editor.InsertText($output)
    function Fix-EditorIndentation
    PARAM(
    [Alias('ISEEditor')][ValidateNotNull()]
    [Parameter(Mandatory, ValueFromPipeline, Position=1)]
    [Microsoft.PowerShell.Host.ISE.ISEEditor]
    $Editor
    $EditorType = $Editor.GetType()
    $SetterInstance = New-Object -TypeName $OptionSetter
    $SetterInstance.Options = $EditorType.GetProperty('EditorOperations', $NonPublicFlags).GetMethod.Invoke($Editor, $null).Options
    $Dispatcher = $EditorType.GetProperty('EditorViewHost', $NonPublicFlags).GetMethod.Invoke($Editor, $null).Dispatcher
    $SetterInstance.Setter = $SetterInstance.Options.GetType().GetMethod('SetOptionValue', [type[]]@([string],[object]))
    $SetterInstance.Dispatch($Dispatcher)
    function Fix-IseIndentation
    [Microsoft.Windows.PowerShell.Gui.Internal.MainWindow] $ISEWindow = (Get-Host | Select-Object -ExpandProperty PrivateData | Select-Object -ExpandProperty Window)
    [Microsoft.Windows.PowerShell.Gui.Internal.RunspaceTabControl] $RSTabCtrl = $ISEWindow.Content[0].Children[2]
    [Microsoft.PowerShell.Host.ISE.PowerShellTab] $PSTab = $RSTabCtrl.Items[0]
    $PSTab.Files | Select-Object -ExpandProperty Editor | Fix-EditorIndentation
    function Invoke-ISEFunction
    PARAM(
    [Parameter(Mandatory, Position=1)]
    [Action] $ScriptBlock
    $ISEWindow = $(Get-Host | Select-Object -ExpandProperty PrivateData | Select-Object -ExpandProperty Window)
    return $ISEWindow.Dispatcher.Invoke($ScriptBlock)
    function Fix-IndentationForAll
    $psISE.PowerShellTabs | Select-Object -ExpandProperty 'Files' | Select-Object -ExpandProperty 'Editor' | Fix-EditorIndentation
    # Startup
    function New-Timer
    PARAM(
    [Alias('Handler')]
    [Parameter(Position=0, Mandatory=$true)]
    $Action,
    [Double]
    [Parameter(Mandatory=$false)]
    $Interval = 50,
    [Boolean]
    [Parameter(Mandatory=$false)]
    $AutoReset = $true
    [System.Timers.Timer] $oTimer = New-Object -TypeName System.Timers.Timer($Interval)
    $ElapsedEvent = Register-ObjectEvent -InputObject $oTimer -EventName 'Elapsed' -Action $Action
    $oTimer.AutoReset = $AutoReset
    return $oTimer
    $(New-Timer {
    Fix-IndentationForAll
    } -Interval 100 -AutoReset $true).Start()

  • Killing a Java process from another Java process

    Hi
    Is there a possible way of sending a SIGINT, SIGKILL, or any other signal from a Java process running in one JVM, to a java process running in a different JVM on the same machine.
    I've the signal handlers written in my process and they do respond to singals (e.g. on pressing Ctrl-C) on the console, but i want to write a separate program that sends this signal to the first process.
    Any ideas?
    Thanks in advance and regards
    Kashif

    The answer, as always, is that Java can't do operating-system-specific things like that, but you can use JNI to do it. However, if your code created the Java process you want to kill, via Process p = Runtime.getRuntime().exec(...), then you can use p.destroy() to kill it.

  • Displaying Chinese in Powershell and Powershell ISE

    I have a PS that retrieves file names and URLs from webpages, download files, display file names and download progress on screen and save files on disk.
    file names are Chinese and were displayed correctly in Chinese both in Powershell console and in Powershell ISE before. But now they are displayed correctly only in Powershell ISE, not in Powershell console anymore. Any suggestion? thanks
     

    I experienced the same with Japanese Characters.
    If you are using Invoke-WebRequest,
    you can try this.
    $JP_MSSITE = Invoke-WebRequest www.microsoft.co.jp
    if ( $JP_MSSITE.BaseResponse.ContentType.Contains("charset=") )
    $TITLE = $JP_MSSITE.ParsedHtml.title
    else
    $METADATAS = $JP_MSSITE.ParsedHtml.getElementsByTagName("meta")
    if ( $METADATAS.charset -ne $null) {
    $CHARSET = $METADATAS.charset
    }else{
    ForEach ($METADATA in $METADATAS) {
    if( $METADATA.charset -ne $null ){
    $CHARSET = $METADATA.charset
    break
    if($METADATA.content -match 'text/html;.*charset=(.*)|charset=(.*);.*text/html')
    $CHARSET = $matches[1]
    break
    try {
    $TITLE =[System.Text.Encoding]::GetEncoding($CHARSET).GetString([System.Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($JP_MSSITE.ParsedHtml.title))
    }catch{
    $TITLE = "Not supported"
    Write-Host $TITLE
    It was asked here.
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/cbf40856-9157-42ae-8127-0328b4664405/cant-show-content-of-invokewebrequest-in-unicode?forum=winserverpowershell#cbf40856-9157-42ae-8127-0328b4664405

  • Reopen last used tabs in Powershell ISE

    Hi Scripting Guys
    I use a lot of tabs in Powershell ISE console in my work, as an Administrator, and every time I close the ISE I need to reopen every tabs that I used before. So my question is:
    When I open Powershell ISE can it automatically reopen last tabs, that I used? Can Powershell ISE remember that last used tabs like IE can remember last open browser session?
    Best regards,
    Thorkell

    Hi,
    I do this by killing the ISE process with process explorer instead of closing the window. The next time you open the ISE it will note that it didn't shut down properly and will reopen the tabs you had open previously.
    I'm not aware of a graceful way to do this though.
    Don't retire TechNet! -
    (Don't give up yet - 12,830+ strong and growing)
    kill $PID -Force
    I've done this a few times to keep my tabs when I open up ISE another time. :)
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

  • Powershell ISE bugs?

    Using PowerShell 3.0 ISE on Windows Server 2008 R2 with the latest service pack. Copy and paste within a PowerShell ISE window or between windows or from the ISE to anything else only works intermittently. There is no other copy and past problem on the servers.
    Also when I modify a PS script and run it Powershell often runs the previous version of the script. Some times I have to save AND close AND reopen to get the revised script instead of the original script to run.
    Is this just my servers?
    carpe cras

    There is a Connect issue reported for Cut, probably could roll this one up into this by adding a comment and voting on it. If you don't think it is related enough, you can always open up a new Connect item as well.
    https://connect.microsoft.com/PowerShell/feedback/details/777187/ctrl-x-cut-keyboard-shortcut-stops-working-in-powershell-ise-after-a-while
    Boe Prox
    Blog |
    PoshWSUS | PoshPAIG |
    PoshChat

  • Powershell ISE v2.0 will not launch 0

    In the process of consolidating and upgrading our 2003 servers to 2008, we wanted to run our current daily Powershell scripts on another server while we upgrade the server we had them running on (also a Server 2003 32-bit).
    I went out and downloaded the v2.0 for server 2003 32-bit (Download the Windows Management Framework Core for Windows Server 2003 package now.) and installed it.  I copied my scripts over to the same folder from the old server and when I tried to open
    the Powershell ISE to do a test run on my scripts I get a pop-up that says:
          "Windows PowerShell ISE has encountered a problem and needs to close.  We are sorry for the inconvenience."
    The only options are Debug and Close.  I have tried to research this on 2003 servers and have not had any luck with a fix.
    The Windows Powershell command area will open up and I can run commands but when I enter  PS C:\> ISE I get the same error as trying to run it from the icon. 
    I have rebooted a couple times and still this persists. I was going to try and uninstall version 2.0 and install v1.0 but inthe add/remove programs it does not show any Powershell applications.
    Any suggestion?
     

    Hi,
    The ISE is a .Net application, are you sure you're up to date with .Net as well?
    Also, FYI if you haven't seen this -
    http://support.microsoft.com/kb/2580993/en-us
    Don't retire TechNet! -
    (Don't give up yet - 12,950+ strong and growing)

  • Long time to start on  Java process dispatcher

    Hi ,
    I am trying to Install Solution Manager. When I attempt to start my sap system, the Java process dispatcher of instance/stage SM1 (solution manager) takes too much time and finally doesn't start showing this intallation error.
    ERROR 2008-09-24 11:01:11.314
    CJS-30151  Java process dispatcher of instance SM1/DVEBMGS00 [ABAP: ACTIVE, Java: (dispatcher: UNKNOWN, server0: RUNNING)] did not start after 2:00 minutes. Giving up.
    ERROR 2008-09-24 11:01:11.502
    FCO-00011  The step startJava with step key |NW_Onehost|ind|ind|ind|ind|0|0|NW_Onehost_System|ind|ind|ind|ind|1|0|NW_CI_Instance|ind|ind|ind|ind|11|0|NW_CI_Instance_StartJava|ind|ind|ind|ind|5|0|startJava was executed with status ERROR .
    Can anyone please let me know what is missing in this procedure? Any idea?
    tkanks in advance.

    Hi Matias,
    What are the parameters you set for your dispatcher?
    Regards
    Val

  • All Java Processes crash on RH Linux 7.3 / 6.3 without any comment

    We have the following Problem on two Machines. We installed j2sdk1.4.0 first, then jdk-1.3.1_04 (Because of other Problems with 1.4.0).
    Now all running java Processes crash after up to two hours without any comment, any error file. Looks like they were killed by the 'kill' Command. The running java Processes are different Programs, that do very different things.
    The OS on the two machines are RH Linux 7.3 and 6.3 - normal installation without any essential changes.
    I would be very happy, if someone have an idea, how to solve this Problem. If you need additional Information, ask for.
    Holger

    ... if someone have an idea, how to solve this Problem.Seems like I remember seeing a problem like that.
    It turned out that indeed it was the 'kill' command. Another process was running, looking for the app, and killing it when it found it.
    We spend quite a bit of time trying to figure out why our app was 'crashing' before deciding to look elsewhere (when we discovered the other process.)

  • How do I stop Java processes from appearing on the dock?

    I have a Java application that has a fairly extensive build process using ant. It builds fine on OSX, but constantly annoys me. There are a large number of unit tests that run using JUnit, and each test starts in a new Java process. The problem is that when each process starts (and there are about 100 during the course of the build), a new Java icon appears on the dock and stays until the process finishes. First of all, that slows down the build (since it has to do all that graphics work to keep changing the appearance of the dock). Secondly, every time a new process starts, it takes away the keyboard focus from whatever I'm currently working on. I either have to click in the window I want again, or else wait for the process to finish.
    On Windows, this is handled with an alternative version of the JVM called "javaw.exe" that does not get a foreground window. However, I see no "javaw" in the Java directory on OSX. Is there some option to start Java with that will stop this dock updating? Note that there are times when I want the dock to be updated (when I'm running a "normal" Java app).

    Even when the Guest Account / Access is disabled, the login option / and lock screen, still have a guest login.
    This is because in Preferences/ Security & Privacy/General the bottom item is turned on.
    Turn on: Disable restarting to Safari when screen is locked

  • How to restart a java process in Oracle AS 10g

    Hi
    In Oracle AS 10g, the java process consumes 50% cpu resource due to the report invoked by a user. Now I need to restart the java back ground process?, please reply me with the syntax or with examples.
    ps -eaf
    CPU PROCESS
    50% /ORACLE_HOME/jdk/jre/bin/java -server -cp /report/oracle
    Thanks in advance
    Bala

    The copy method being using is unsupported, hence the target Portal would be in an unsupported state.
    This is unsupported as per the following note:
    Note 333867.1 - Portal Export and Import Utility Supportability Scenarios :
    Copy operations after an object is renamed:
    Exporting and importing a page group, then renaming the page group on the target system (to create a copy) and repeating the export and import operation.
    OR:
    Exporting and importing a page group, then renaming the same in source or target and repeating the export and import operation.
    Not supported.
    Please do not rename objects if you plan to perform export and import operations.
    Note: The display name can be changed, but internal name change is considered a renaming operation.
    In 10.1.4, renaming is supported, but renaming page group and pages with the intention of copying them is not supported..."

  • Java process - high CPU usage

    Hi,
    I'm describing a high CPU scenario which gets triggered randomly ( I'm not able to replicate it on my lab setup).
    There are around 120 threads which are running in my java process. The jvm is running on a high traffic (through put) site, where there are a lot of async events coming to the java process.( around 220 events per 60 seconds ). The java process works fine in this scenario, the normal CPU consumption hovers around 1.5 % to 2.0 %.
    But, at times, I've seen CPU to be as high as 43 %, and it stays at that value for hours altogther. In those situations, I usually do a failover to standby java process. I tried debugging the issue to see which java thread could be causing the issue, but, I could not come to a conclusion or replicate the situation in lab environment.
    Here are the details of the execution environment
    java -version
    java version "1.4.2_11"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
    Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)
    prstat during high CPU
    PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
    10485 root 120 10 0 570M 381M cpu1 268:10 43.64% java
    prstat -Lm -p output
    PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/LWPID
    10485 root 53 0.5 0.2 0.0 0.0 30 0.2 16 69 1K 118 0 java/2
    10485 root 31 0.0 0.1 0.0 0.0 53 0.2 16 23 778 93 0 java/26
    10485 root 0.4 0.0 0.0 0.0 0.0 99 0.0 0.1 10 16 106 0 java/12
    10485 root 0.1 0.0 0.0 0.0 0.0 100 0.0 0.0 3 2 7 0 java/15
    10485 root 0.1 0.0 0.0 0.0 0.0 97 0.0 2.4 120 3 128 0 java/41
    10485 root 0.1 0.0 0.0 0.0 0.0 97 0.0 2.5 120 4 131 0 java/410
    Some more points about the last prstat -Lm output.
    java/2 is "VM Thread" ( responsible for GC). "VM Thread" is having a NORMAL priority ( 5 )
    java/26 is a "Worker" thread, with priority MINIMUM ( 1 ).
    Could you suggest what could be issue, and what other information I could collect to find out the issue. Its difficult to profile the process because the problem scenario is difficult to ascertain and the process is running on a production setup.
    Any help is appreciated.
    Thanks
    Sanjay

    Hi,
    Thanks for your response. Both, the production setup and lab setup have have 2 physical CPUs.
    Actually, there are two java threads ( machine is solaris 10) one is "VM Thread" and other is my applications worker thread. (there are 10 of them with priority 1). If you look at the top two lwps in the prstat -Lm , both are showing high value of ICX.
    I'm still not able to drill down to my code level. (Worker thread is waiting on a queue to de-queue server request). Could you give some hint to move foward?
    rgds
    Sanjay

  • Java Process with High CPU

    I have a java process running on HP-UX with a 1.4.2 JVM. This program is using some third-party code (quartz) to act as a batch scheduler similar to cron. When running in production, the process runs fine for several days and then starts maxing out the CPU. The server has 8 cpu's and the last time the problem occured, 4 of the cpu's were 100% in use with this process.
    I've tried sending a "kill -3 pid" but I can't seem to get a thread dump. I've eventually gotten some 700Meg core files. Is there anyway to use these core files to tell me what is going on?
    Any ideas on how to trouble shoot this problem? We've used some profilers but we can't duplicate the problem on test servers so we aren't learning anything new.
    Thanks,
    Brian

    Try pstack to read the stacks of the threads in the process.
    Try pldd to determine the shared libraries in the process then
    use truss to trace calls in any of these libraries to determine where
    the cycles are being spent.

  • I need to break the install process

    Hi,
    I recently tried to run an archive and install on my G5 Mac - Dual 2ghz - 1 gb ram OSX Version 10.4.11.
    Unfortunately, I am missing the "correct" version of disk 2. As a result, I cannot continue with the install. Nor can I do anything with this drive, since it goes straight into the installer and asks for disk 2.
    I can put the drive in another identical Mac G5 and see all of the data on the drive including the "Previous Versions" folder, and the "new" system folder.
    If I delete the "new" system folder and put it back into Mac-A I get a Kernal panic - missing drivers screen.
    So, either
    A: How do I break the boot process to start over with a different set on the original machine; or
    B: what file do I need to delete from the hard drive (using the second machine) to allow me to restart the process (using a different OS ver.?
    Thanks!

    You really can't break the installation process midstream. You can attempt to fix a mistaken install using an Archive and Install, and combo update back to the version you were at last, but that's dependent on their being enough space on your system*:
    http://www.macmaps.com/diskfull.html
    After an archive and install, you can migrate data back to your new system that is usable. Frequently added drivers and plugins are not usable, but applications may be usable from a previous system.
    This is why it is so important you backup your data before installing anything*:
    http://www.macmaps.com/backup.html
    If you haven't you can backup even a shoddy system and restore elements such as documents, but don't expect anything else to be usable.
    - * Links to my pages may give me compensation.

  • Ps -p running very slow (1-2 seconds) on Java process

    Hi Solaris gurus:
    I encountered a issue that running ps -p on java process running very slow, it took almost 2 seconds to complete.
    I issued a truss on the "ps -p " command, the following is part of the output:
    /1: 0.0001 fstat(1, 0xFFFFFFFF7FFFE1F0) = 0
    /1: 0.0000 write(1, " U I D P".., 55) = 55
    /1: 0.0002 open("/proc/19299/psinfo", O_RDONLY) = 3
    */1: 1.3170 read(3, "02\0\0\0\0\0\011\0\0 K c".., 416) = 416*
    /1: 1.2401 close(3) = 0
    /1: 0.0002 stat("/dev/tty", 0xFFFFFFFF7FFFE830) = 0
    It seems that the read() spent the most time.
    Anyone can help?

    Not enough memory, page-outs is too large
    8.91 GB    Page-outs
    After removing adware, and do a safe boot of Safari and remove extensions, then reset cache history etc. You need to do a boot into Recovery Mode and run Disk Repair from there. Also boot the system in Safe Mode.
    On startup it sounds like you have a problem with the directory which would also account for long startups and checking the directory. Along with or instead of DU Repair Disk you can use Single User Mode and fsck -fy to try to fix the directory but in some cases that may not be enough.
    Backups from before you got this adware and problems helps and should always be ready and able to restore a system from known good backups or system restore image.
    4GB of RAM may have been fine originally but "Early 2011" is now 5 years and 4 OS version changes. You can upgrade the memory and while at it consider a nice SSD internal drive which will help as well. Take a look and see what prices and options there are from http://www.macsales.com for your 2011 MacBook Pro.
    http://www.everymac.com
    Community for MBP MacBook Pro

Maybe you are looking for