Store Ctrl+C Char

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Store Ctrl+C Char

#1 Post by Meerkat » 16 Aug 2015 07:25

I saw this topic: viewtopic.php?f=3&t=5860 automating the Bell character. Now, is there a way to store the Ctrl+C character as a variable?

Meerkat

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Store Ctrl+C Char

#2 Post by npocmaka_ » 16 Aug 2015 07:51

This is EXT character - DEC/HEX/OCT code is 03.

Check GenCHR
or Certutil
or dbenham's forfiles subtoutine:

Code: Select all

http://www.dostips.com/forum/viewtopic.php?p=23888 


(I can put only two links so the last one is in code block)

it is possible also with mshta,WSH/JScript/VBScript,powershell,built-in .net compilers.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Store Ctrl+C Char

#3 Post by foxidrive » 16 Aug 2015 07:55

Using the same technique - control c is ascii character 3

Code: Select all

@echo off
for /f %%i in ('forfiles /m "%~nx0" /c "cmd /c echo 0x03"') do set "cc=%%i"
>file.txt echo "%cc%"

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: Store Ctrl+C Char

#4 Post by Meerkat » 16 Aug 2015 08:05

I tried this:

Code: Select all

@echo off
setlocal

::Define a Linefeed variable
set LF=^


::above 2 blank lines are critical - do not remove.


call :hexprint "0x03" var
set var

exit /b

:hexPrint  string  [rtnVar]
  for /f eol^=^%LF%%LF%^ delims^= %%A in (
    'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
  ) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
exit /b


...but this is the output:

Code: Select all

var=♥


Meerkat

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Store Ctrl+C Char

#5 Post by dbenham » 16 Aug 2015 08:12

Meerkat wrote:...but this is the output:

Code: Select all

var=♥

Yep - That is how the console displays a Ctrl-C (0x03) character :D


Dave Benham
Last edited by dbenham on 16 Aug 2015 08:16, edited 2 times in total.

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: Store Ctrl+C Char

#6 Post by Meerkat » 16 Aug 2015 08:16

dbenham wrote:
Meerkat wrote:...but this is the output:

Code: Select all

var=♥

Yep - That is how the console displays a Ctrl-C (0x03) character :D


Dave Benham


Yeah, that's quite weird. Sorry I thought that "heart" symbol is not the char (I am new into this), but I applied it to my code and it works smoothly! :shock:

Thanks everyone!

Meerkat

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Store Ctrl+C Char

#7 Post by dbenham » 16 Aug 2015 08:17

Depending on your goal, you might find this link useful: Programmatically "press" Ctrl-C / Exit batch inside CALL


Dave Benham

Post Reply