0

I'm forced to use DOS to write some batch scripts. How to do arithmetic operations on variables? How to re-write the last line?

FOR %%f IN (*.ogg) DO CALL :runsox "%%f"
del temp.ogg tmpfile
GOTO :EOF

:runsox
soxi -D %1>tmpfile

SET /P decvalue=<tmpfile * 1.2

Update:: Following bhu1st's post, I couldn't see exactly how to apply that to my script. But GNU bash has the same problem, cannot operate on floating point numbers. The way to solve this in bash is to calculate the value with an bc, a command line calculator. I download a command line calculator. and use as in the line:

calcoo %decvalue%*1.2>tmpfile
naim5am
  • 1,334
  • 3
  • 17
  • 33
  • there's no `set /p` or `set /a` in DOS. [DOS and Windows cmd are completely different things](https://superuser.com/a/1411173/241386) – phuclv Dec 13 '20 at 04:51

3 Answers3

0

Try this:

SET /P tmpvalue=<tmpfile
SET /A decvalue=tmpvalue * 1.2

But even then, the result will be truncated. No decimals.

muratgu
  • 7,241
  • 3
  • 24
  • 26
  • did you try that ? set /a decvalue = tmpvalue * 1.2 says - Missing Operator on Dos 6.1 you may try simple operation like set /a x = 2 * 2.2 to see that – bhu1st Mar 06 '11 at 07:29
0

I tried running simplified arithmetic expression with floating point multiplication, interpreter says Missing Operator. I found that, Batch files as such do not support the floating point arithmetic.

this might point you to right direction: Floating point division in a dos batch

Community
  • 1
  • 1
bhu1st
  • 1,282
  • 11
  • 23
0
FOR %%f IN (*.ogg) DO CALL :runsox "%%f"
del temp.ogg tmpfile
GOTO :EOF

:runsox
soxi -D %1>tmpfile
SET /P decvalue=<tmpfile
calc %decvalue%*1.2>tmpfile
SET /P decvalue=<tmpfile

Ugly, but works. Download calc from http://download.cnet.com/Command-Line-Calculator/3000-2094_4-10897229.html

naim5am
  • 1,334
  • 3
  • 17
  • 33