0

Hey I'm trying to create a function that parses a string passed via a browser protocol. It's a "callto://" protocol and it is in this format: "callto://5551234567/" with the persons phone number inside there. I need to extract the number and pass it to another program that dials the number. The syntax for that other program is like this: "CallClerk.exe dial=5551234567=".

I'm a beginner to batch however, and can't figure out exactly what to do. Here's my current code:

@echo off
set var=%1
set number=theirphone
FindStr /R "callto://(..........)/" %var% > %number%
start C:\Program Files (x86)\CallClerk\CallClerk.exe dial=%number%=
Exit /B

Thanks for the help!

3
  • Findstr can't parse a variable by itself, it needs eg. echo. Nevertheless you should display the %var%. Commented May 30, 2013 at 16:04
  • Okay cool can you give me an example of how to correctly use the FindStr command? I'm not familiar enough with batch syntax... Commented May 30, 2013 at 16:08
  • Just enter help findstr on the Windows shell command prompt. Commented May 30, 2013 at 16:13

3 Answers 3

1
@echo off
FOR /f "tokens=2 delims=/" %%i IN ('echo %~1') DO start "" "C:\Program Files (x86)\CallClerk\CallClerk.exe" dial=%%i=
Exit /B

should work for you (untested) - assuming your input parameter is callto://5551234567/

Note the use of quoting - the .exe needs to be quoted since it contains a space in the path. The extra pair of quotes in the window-name. If you like, you could replace that pair with "Calling %%i". This parameter is optional, but inserting it ensures that START doesn't get confused between window-title, executable-name and parameter-to-executable.

Sign up to request clarification or add additional context in comments.

4 Comments

Okay what if I wanted to do the same thing except the input parameter is tel:+15551234567? Can I use that same code but with two separate delims?
Nevermind! Got it working with this: @echo off FOR /f "tokens=2 delims=+1" %%i IN ('echo %~1') DO start "" "C:\Program Files (x86)\CallClerk\CallClerk.exe" dial=%%i= Exit /B
Yes - use "tokens=2delims=+/" and that should handle both situations. The idea is that the variable is parsed into a sequence of 'tokens' separated by delimiters. The first token would be everything up to the first delimiter, the second from that delimiter to the next. Any character between the = and " is a delimiter - and that can include space if you like (but the space always directly before the ")
Oh - your +1 won't work. You'll find that the number will be truncated at the first 1 in the phone number. You'd need to use "tokens=1*delims=+1" and dial %%j not %%i. But that will only work for US/CAN numbers (start +1) - for other countries, the prefix is not only a different number, but it's not of a consistent length - and neither is the local telephone number...
1

This works to extract numbers from a string.

It uses two for loops, the first one gathers all the non-numeric characters and they are used as delimiters in the second for loop to gather the numerics and dial the number.

Strings of variable lengths can be handled, as long as all numbers are used in the desired telephone number.

If you want to keep the + as a valid telephone character then include it in the first for command in the delims with the numbers.

@echo off
set "var=callto://5551234567/"

for /f "delims=0123456789" %%a in ("%var%") do set "delims=%%a"
for /f "delims=%delims%" %%a in ("%var%") do (
start "" "C:\Program Files (x86)\CallClerk\CallClerk.exe" dial=%%a=
)

Comments

0

You should be able to use a regex along the lines of (?<=callto:\/\/)[\d]+(?=\/) to grab the number itself. This uses a positive look ahead and look behind to make sure you are matching at least one number that is preceded by the callto:// and followed by a /.

If you left it as something like callto:\/\/[\d]+\/, then it is matching the entire string and will return back with the callto text included. If you are intending to pass just the numbers along to the next part of you code, extract them using the look ahead to guarantee the before and after conditions are met.

I did a quick test using the strings you used in your example. You can see the regex in action here.

4 Comments

Findstr unfortunately doesn't support most of your Regex.
Thanks! Now I just have to get things working on the batch side of things.
@MrGrinst your call to your exe has spaces in it, spaces are normally bad. You may need to surround the path to the exe in some kind of quotes :)
I would prefer double quotes " "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.