Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Stop a command in the middle of its operation

Feb
240
3
In the regular DOS command prompt, I can hit Ctrl-C to stop an operation in its tracks. So, let's say I run a long operation in a loop, iterating over all subdirectories, like this:
for /d /r %G in ("*") do [command] %G
with the regular command prompt, I can stop it at any time with Ctrl-C. However, I can't find any way to do so in TCC. To be sure, there is an option to support Ctrl-C in batch files, but that doesn't seem to help here (perhaps because this is not a batch file with multiple lines, but rather a single line command).
As far as I can tell, the only thing I can do to stop it is to close the TCC window altogether - not a great solution because I lose all my history!
 
Well, I'm running a custom utility that I wrote, but I can reproduce the problem with the simple "dir" command. Go to your root directory and run:
dir /s
This will recurse through all directories, outputting all files. On my system, with nearly a million files, this takes a bit of time, even in TCC. I would expect, however, to be able to stop it with Ctrl-C. However, Ctrl-C does not work for me.
Similarly, if we do the same thing in a for loop on the command line, like this:
for /d /r %G in ("*") do dir %G
Here too, Ctrl-C does not affect it
 
OK, I found the problem. When I first installed TCC, I wanted to copy and paste text as I was used to, and it seems strange that I could not do it with Ctrl-C, so I set Ctrl-C to be "copy" in my keyboard shortcuts. But it seems that in doing so, I canceled my ability to break within a program!
Thanks anyway for your help.
 
DIR /S is what I tried, and Control-C definitely interrupts it here.

Is this in a Take Command tab, or in a standalone TCC console? If you're having the issue in a Take Command tab, you might go to Options / Configure Take Command... / Tabs, and check that the tick boxes marked 'Left Ctrl Key' and 'Right Ctrl Key' are both turned off.
 
OK, I found the problem. When I first installed TCC, I wanted to copy and paste text as I was used to, and it seems strange that I could not do it with Ctrl-C, so I set Ctrl-C to be "copy" in my keyboard shortcuts. But it seems that in doing so, I canceled my ability to break within a program!

Aha; that makes sense! I'd forgotten there was such an option.
 
OK, I found the problem. When I first installed TCC, I wanted to copy and paste text as I was used to, and it seems strange that I could not do it with Ctrl-C, so I set Ctrl-C to be "copy" in my keyboard shortcuts. But it seems that in doing so, I canceled my ability to break within a program!

The problem is that you want to overload Ctrl-C to mean two different things. You can actually do that with Take Command by specifying one Ctrl key (left or right) that will be handled by Take Command; the other one will be passed to the current tab window. So for example, a (left)Ctrl-C can copy, and a (right)Ctrl-C can interrupt.
 
This thread is old but the case i have is directly relevant to it. Can someone help with this :dummy:

Ctrl-C doesn't work while "pause" is executing (Press any key to continue . . .) within a procedure. I have a loop with "pause" added during testing time. The code I am using is to loop through direct sub-folders then for each subfolder execute a call to an executable (.exe) named here CmdThatTakesLongTimeToRun. During testing I'm replacing the call to the executable with an echo of what it will look like. Somehow in doing so Ctrl-C doesn't work and I have to press a number of times equal to direct subfolders until the for loop completes!


My Looks like this:

set par_test_DoSmthProcedure =Yes
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set parentFolder=%cd%
for /f "tokens=*" %%x in ('dir /b/ad') do (
cd "%%x"
echo processing folder "%%x"
pause
call :DoSmthProcedure
cd "%parentFolder%"
)
goto :eof

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DoSmthProcedure

if defined par_test_DoSmthProcedure (

echo.CmdThatTakesLongTimeToRun%parameters%
) ELSE (
CmdThatTakesLongTimeToRun %parameters%
)
echo.Completed @ %date% -- %time%
exit /b

:eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


The example below is the output I get whether i press ctrl-c every time or any other key, kind of stuck until done :banghead: . The output of echo in DoSmthProcedure is omitted for clarity.

processing folder "pdf"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:14.67
processing folder "mp4"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:15.09
processing folder "jpg"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:15.30
processing folder "wmv"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:15.43
processing folder "mts"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:15.69
processing folder "avi"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:15.83
processing folder "bmp"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:16.07
processing folder "png"
Press any key to continue . . .
Complete Time @ 10/21/2017 -- 13:55:16.83
processing folder "vob"
Press any key to continue . . .
 
@Sam40 hve you tried "ON BREAK" ??

Activation of ON BREAK
ON BREAK will execute command if the user presses Ctrl-C or Ctrl-Break.

or
Purpose: Enable or disable Ctrl-C and Ctrl-Break
Format: BREAK [ON | OFF]
Usage:
BREAK OFF will disable all Ctrl-C and Ctrl-Break handling in TCC (though not necessarily in child processes). In CMD, BREAK OFF doesn't actually do anything, so setting it in TCC will introduce a possible incompatibility with existing batch files.
 
And there is a "Cancel batch file on Ctrl-C" check-box in OPTION\Startup.
 
@Sam40
I'm wondering if you can get rid of the cmd.exe-style instructions and go to a fully Take-Command-ish approach. I've tried the following under TCC 20 (I'm always slow to upgrade) and it displays what I expect it to display. If your batch file must be fully compatible with cmd.exe, none of the following applies. In which case, this reply can maybe be used for wrapping fish or something. :)

Code:
setlocal
on break CANCEL
set par_test_DoSmthProcedure=Yes

do _thisdir in /s /a:d *
    pushd "%@full[%_thisdir]"
    echo  Processing in %_cwd
    pause Quit: Control+C -- or press some other key to continue...
    iff defined par_test_DoSmthProcedure then
        echo  do one kind of procedure
    else
        echo  do some other kind of procedure
    endiff
    echo  Completed: %_date @ %_time
    echo.
    popd
enddo
 

Similar threads

Back
Top