DCoT Apps: Command Line Calculator
This is such a simple idea and script that I’m putting the whole thing out there as open source immediately! Essentially, I was looking for an easier way to perform simple calculation quickly. I thought that all of the tools for calculations are there already, I just need an easier way to access them. So, I wrote the Command Line Calculator.
Really, all this script does is take whatever you type after it and then feed it into the built in Windows Calculator. So, if you want to find out what 45 times 99 was, you would simply type clcalc 45*99= and then press the Enter key. This will open up the Windows Calculator and then enter the equation that you want calculated. Then, it will display the results.
To install the Command Line Calculator, simply download it and save it in your Windows directory (usually C:\Windows). Then, you will be able to access it from the Run.. command (pre-Vista) or the Search (Vista). It is also available from the command line “DOS box”.
If you are interested in the source code, here it is:
;clcalc #NoTrayIcon Dim $Keystrokes Run("calc.exe",@WindowsDir) If $CmdLine[0]<>1 Then Exit Else $Keystrokes = $CmdLine[1] WinActivate("Calculator") WinWaitActive("Calculator","",5) Send($Keystrokes) Exit EndIf
Download this code: clcalc.au3
Like I said, not rocket science but useful nonetheless.
If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?
5 Responses to “DCoT Apps: Command Line Calculator”
-
Kim Jalun Says:
May 18th, 2007 at 9:03 amFYI:
The DOS SET command has a /A switch which allows for signed integer arithmetic (I believe this was introduced in Windows 2000).
Your example:
c:\>SET /A 45*99
4455Applicable help (SET /?)
The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated. The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:() - grouping
! ~ - - unary operators
* / % - arithmetic operators
+ - - arithmetic operators
> - logical shift
& - bitwise and
^ - bitwise exclusive or
| - bitwise or
= *= /= %= += -= - assignment
&= ^= |= >=
, - expression separatorIf you use any of the logical or modulus operators, you will need to
enclose the expression string in quotes. Any non-numeric strings in the
expression are treated as environment variable names whose values are
converted to numbers before using them. If an environment variable name
is specified but is not defined in the current environment, then a value
of zero is used. This allows you to do arithmetic with environment
variable values without having to type all those % signs to get their
values. If SET /A is executed from the command line outside of a
command script, then it displays the final value of the expression. The
assignment operator requires an environment variable name to the left of
the assignment operator. Numeric values are decimal numbers, unless
prefixed by 0x for hexadecimal numbers, and 0 for octal numbers.
So 0×12 is the same as 18 is the same as 022. Please note that the octal
notation can be confusing: 08 and 09 are not valid numbers because 8 and
9 are not valid octal digits. -
Tim Fehlman Says:
May 18th, 2007 at 9:12 amKim Jalun,
I didn’t know about that little trick. Thanks for the heads up, Kim!
Tim
-
Marshall Jiang Says:
May 18th, 2007 at 3:37 pmSince I have Python installed on my computer, I just type in
C:/> python
and type in the problem into the interactive prompt
-
Robert Says:
May 20th, 2007 at 6:07 pmI downloaded your calculator, because this is something I’ve always needed (I’m too lazy to open the calculator each time). I did a simple test, 3+3, and, somehow, it came out as 27. Don’t know if I did something wrong, or if it’s the windows calculator or your command-line thingy that screws it up… Just thought you should know.
-
fredrik Says:
June 20th, 2007 at 3:00 pmCheck this commandline calculator
CLC 10+10*45%
And the result will be presented to you in a messagebox and you could even get the result in the clipboard.

