Batch file 批处理Jscript混合计算器
这是我的代码:Batch file 批处理Jscript混合计算器,batch-file,jscript,Batch File,Jscript,这是我的代码: @if (@codesection==@batch) @then @echo off title C: cd %windir%\System32 set c=echo :a %c%abs: Absolute Value %c%atn: Arctangent %c%cos: Cosine in Degrees %c%exp: e Raised to the Power of %c%hex: Hexadecimal Value %c%int: Integer Part %c%l
@if (@codesection==@batch) @then
@echo off
title
C:
cd %windir%\System32
set c=echo
:a
%c%abs: Absolute Value
%c%atn: Arctangent
%c%cos: Cosine in Degrees
%c%exp: e Raised to the Power of
%c%hex: Hexadecimal Value
%c%int: Integer Part
%c%log: Natural Logarithm
%c%oct: Octal Value
%c%rnd: Random Number from (0,1)
%c%sgn: Sign
%c%sin: Sine in Degrees
%c%sqr: Square Root
%c%tan: Tangent in Degrees
echo.
if defined a goto b
set /p a=
cls
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set b=%%G
goto a
:b
%c%%a%=%b%
echo.
goto:eof
@end
WScript.Echo("Math."+WScript.Arguments(0));
我不明白我在哪里使用了不正确的语法,如果有人能帮我修改这个脚本,我将不胜感激。您的代码有一些问题。JScript中的所有数学函数都必须使用以下格式编写:
Math.function(argument)
,例如:Math.sqrt(25)
;您可以查阅此格式的说明
在JScript中,WScript.Echo
是一个函数,因此它使用括号括起参数:
WScript.Echo(eval(WScript.Arguments(0)));
看
在定界@end
之前需要一个goto:EOF
,否则JScript代码将作为批处理代码执行
编辑:回复评论
您没有指出所需的输出,因此我对其进行了修改。这是我的版本:
@if (@codesection==@batch) @then
@echo off
set "c=echo "
%c%abs: Absolute Value
%c%atan: Arctangent
%c%cos: Cosine in Radians
%c%exp: e Raised to the Power of
%c%floor: Integer Part
%c%log: Natural Logarithm
%c%random: Random Number from [0,1)
%c%sin: Sine in Radians
%c%sqrt: Square Root
%c%tan: Tangent in Radians
echo.
:a
set "a="
set /p a=
if not defined a goto :EOF
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set b=%%G
%c%%a%=%b%
goto a
@end
WScript.Echo(eval("Math."+WScript.Arguments(0)));
输出示例:
C:\> test
abs: Absolute Value
atan: Arctangent
cos: Cosine in Radians
exp: e Raised to the Power of
floor: Integer Part
log: Natural Logarithm
random: Random Number from [0,1)
sin: Sine in Radians
sqrt: Square Root
tan: Tangent in Radians
abs(3-5)
abs(3-5)=2
cos(Math.PI/3)
cos(Math.PI/3)=0.5
exp(1)
exp(1)=2.71828182845905
log(10)
log(10)=2.30258509299405
random()
random()=0.137126887153577
random()
random()=0.174421542333208
sin(Math.PI/2)
sin(Math.PI/2)=1
sin(Math.PI/3)
sin(Math.PI/3)=0.866025403784439
sin(Math.PI/4)
sin(Math.PI/4)=0.707106781186547
sqrt(2)
sqrt(2)=1.4142135623731
tan(Math.PI/4)
tan(Math.PI/4)=1
您的代码有一些问题。JScript中的所有数学函数都必须使用以下格式编写:
Math.function(argument)
,例如:Math.sqrt(25)
;您可以查阅此格式的说明
在JScript中,WScript.Echo
是一个函数,因此它使用括号括起参数:
WScript.Echo(eval(WScript.Arguments(0)));
看
在定界@end
之前需要一个goto:EOF
,否则JScript代码将作为批处理代码执行
编辑:回复评论
您没有指出所需的输出,因此我对其进行了修改。这是我的版本:
@if (@codesection==@batch) @then
@echo off
set "c=echo "
%c%abs: Absolute Value
%c%atan: Arctangent
%c%cos: Cosine in Radians
%c%exp: e Raised to the Power of
%c%floor: Integer Part
%c%log: Natural Logarithm
%c%random: Random Number from [0,1)
%c%sin: Sine in Radians
%c%sqrt: Square Root
%c%tan: Tangent in Radians
echo.
:a
set "a="
set /p a=
if not defined a goto :EOF
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set b=%%G
%c%%a%=%b%
goto a
@end
WScript.Echo(eval("Math."+WScript.Arguments(0)));
输出示例:
C:\> test
abs: Absolute Value
atan: Arctangent
cos: Cosine in Radians
exp: e Raised to the Power of
floor: Integer Part
log: Natural Logarithm
random: Random Number from [0,1)
sin: Sine in Radians
sqrt: Square Root
tan: Tangent in Radians
abs(3-5)
abs(3-5)=2
cos(Math.PI/3)
cos(Math.PI/3)=0.5
exp(1)
exp(1)=2.71828182845905
log(10)
log(10)=2.30258509299405
random()
random()=0.137126887153577
random()
random()=0.174421542333208
sin(Math.PI/2)
sin(Math.PI/2)=1
sin(Math.PI/3)
sin(Math.PI/3)=0.866025403784439
sin(Math.PI/4)
sin(Math.PI/4)=0.707106781186547
sqrt(2)
sqrt(2)=1.4142135623731
tan(Math.PI/4)
tan(Math.PI/4)=1
您的代码有一些问题。JScript中的所有数学函数都必须使用以下格式编写:
Math.function(argument)
,例如:Math.sqrt(25)
;您可以查阅此格式的说明
在JScript中,WScript.Echo
是一个函数,因此它使用括号括起参数:
WScript.Echo(eval(WScript.Arguments(0)));
看
在定界@end
之前需要一个goto:EOF
,否则JScript代码将作为批处理代码执行
编辑:回复评论
您没有指出所需的输出,因此我对其进行了修改。这是我的版本:
@if (@codesection==@batch) @then
@echo off
set "c=echo "
%c%abs: Absolute Value
%c%atan: Arctangent
%c%cos: Cosine in Radians
%c%exp: e Raised to the Power of
%c%floor: Integer Part
%c%log: Natural Logarithm
%c%random: Random Number from [0,1)
%c%sin: Sine in Radians
%c%sqrt: Square Root
%c%tan: Tangent in Radians
echo.
:a
set "a="
set /p a=
if not defined a goto :EOF
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set b=%%G
%c%%a%=%b%
goto a
@end
WScript.Echo(eval("Math."+WScript.Arguments(0)));
输出示例:
C:\> test
abs: Absolute Value
atan: Arctangent
cos: Cosine in Radians
exp: e Raised to the Power of
floor: Integer Part
log: Natural Logarithm
random: Random Number from [0,1)
sin: Sine in Radians
sqrt: Square Root
tan: Tangent in Radians
abs(3-5)
abs(3-5)=2
cos(Math.PI/3)
cos(Math.PI/3)=0.5
exp(1)
exp(1)=2.71828182845905
log(10)
log(10)=2.30258509299405
random()
random()=0.137126887153577
random()
random()=0.174421542333208
sin(Math.PI/2)
sin(Math.PI/2)=1
sin(Math.PI/3)
sin(Math.PI/3)=0.866025403784439
sin(Math.PI/4)
sin(Math.PI/4)=0.707106781186547
sqrt(2)
sqrt(2)=1.4142135623731
tan(Math.PI/4)
tan(Math.PI/4)=1
您的代码有一些问题。JScript中的所有数学函数都必须使用以下格式编写:
Math.function(argument)
,例如:Math.sqrt(25)
;您可以查阅此格式的说明
在JScript中,WScript.Echo
是一个函数,因此它使用括号括起参数:
WScript.Echo(eval(WScript.Arguments(0)));
看
在定界@end
之前需要一个goto:EOF
,否则JScript代码将作为批处理代码执行
编辑:回复评论
您没有指出所需的输出,因此我对其进行了修改。这是我的版本:
@if (@codesection==@batch) @then
@echo off
set "c=echo "
%c%abs: Absolute Value
%c%atan: Arctangent
%c%cos: Cosine in Radians
%c%exp: e Raised to the Power of
%c%floor: Integer Part
%c%log: Natural Logarithm
%c%random: Random Number from [0,1)
%c%sin: Sine in Radians
%c%sqrt: Square Root
%c%tan: Tangent in Radians
echo.
:a
set "a="
set /p a=
if not defined a goto :EOF
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set b=%%G
%c%%a%=%b%
goto a
@end
WScript.Echo(eval("Math."+WScript.Arguments(0)));
输出示例:
C:\> test
abs: Absolute Value
atan: Arctangent
cos: Cosine in Radians
exp: e Raised to the Power of
floor: Integer Part
log: Natural Logarithm
random: Random Number from [0,1)
sin: Sine in Radians
sqrt: Square Root
tan: Tangent in Radians
abs(3-5)
abs(3-5)=2
cos(Math.PI/3)
cos(Math.PI/3)=0.5
exp(1)
exp(1)=2.71828182845905
log(10)
log(10)=2.30258509299405
random()
random()=0.137126887153577
random()
random()=0.174421542333208
sin(Math.PI/2)
sin(Math.PI/2)=1
sin(Math.PI/3)
sin(Math.PI/3)=0.866025403784439
sin(Math.PI/4)
sin(Math.PI/4)=0.707106781186547
sqrt(2)
sqrt(2)=1.4142135623731
tan(Math.PI/4)
tan(Math.PI/4)=1
如果没有明确的迹象表明您试图获得什么,这可能是一种近似
@if (@codesection==@batch) @then
@echo off
set "c=echo "
:a
%c%abs: Absolute Value
%c%atn: Arctangent
%c%cos: Cosine in Degrees
%c%exp: e Raised to the Power of
%c%hex: Hexadecimal Value
%c%int: Integer Part
%c%log: Natural Logarithm
%c%oct: Octal Value
%c%rnd: Random Number from (0,1)
%c%sgn: Sign
%c%sin: Sine in Degrees
%c%sqr: Square Root
%c%tan: Tangent in Degrees
echo.
set "a="
set /p "a=?"
if not defined a goto b
cls
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set "b=%%G"
%c%%a%=%b%
echo.
goto a
:b
pause
exit /b
@end
WScript.Echo( WScript.Arguments(0) );
- 代码已稍微重新组织李>
- 对“Eval”的调用已被删除(我不知道您要评估什么),在JS中,它是
(JS区分大小写)李>Eval
- 括号已添加到WScript.Echo(在JS中,所有函数调用都包含括号)李>
已添加到批处理结束部分,以避免执行到达JS部分exit/b
- 如果没有明确说明您试图获得什么,这可能是一种近似
@if (@codesection==@batch) @then
@echo off
set "c=echo "
:a
%c%abs: Absolute Value
%c%atn: Arctangent
%c%cos: Cosine in Degrees
%c%exp: e Raised to the Power of
%c%hex: Hexadecimal Value
%c%int: Integer Part
%c%log: Natural Logarithm
%c%oct: Octal Value
%c%rnd: Random Number from (0,1)
%c%sgn: Sign
%c%sin: Sine in Degrees
%c%sqr: Square Root
%c%tan: Tangent in Degrees
echo.
set "a="
set /p "a=?"
if not defined a goto b
cls
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set "b=%%G"
%c%%a%=%b%
echo.
goto a
:b
pause
exit /b
@end
WScript.Echo( WScript.Arguments(0) );
- 代码已稍微重新组织李>
- 对“Eval”的调用已被删除(我不知道您要评估什么),在JS中,它是
(JS区分大小写)李>Eval
- 括号已添加到WScript.Echo(在JS中,所有函数调用都包含括号)李>
已添加到批处理结束部分,以避免执行到达JS部分exit/b
- 如果没有明确说明您试图获得什么,这可能是一种近似
@if (@codesection==@batch) @then
@echo off
set "c=echo "
:a
%c%abs: Absolute Value
%c%atn: Arctangent
%c%cos: Cosine in Degrees
%c%exp: e Raised to the Power of
%c%hex: Hexadecimal Value
%c%int: Integer Part
%c%log: Natural Logarithm
%c%oct: Octal Value
%c%rnd: Random Number from (0,1)
%c%sgn: Sign
%c%sin: Sine in Degrees
%c%sqr: Square Root
%c%tan: Tangent in Degrees
echo.
set "a="
set /p "a=?"
if not defined a goto b
cls
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set "b=%%G"
%c%%a%=%b%
echo.
goto a
:b
pause
exit /b
@end
WScript.Echo( WScript.Arguments(0) );
- 代码已稍微重新组织李>
- 对“Eval”的调用已被删除(我不知道您要评估什么),在JS中,它是
(JS区分大小写)李>Eval
- 括号已添加到WScript.Echo(在JS中,所有函数调用都包含括号)李>
已添加到批处理结束部分,以避免执行到达JS部分exit/b
- 如果没有明确说明您试图获得什么,这可能是一种近似
@if (@codesection==@batch) @then
@echo off
set "c=echo "
:a
%c%abs: Absolute Value
%c%atn: Arctangent
%c%cos: Cosine in Degrees
%c%exp: e Raised to the Power of
%c%hex: Hexadecimal Value
%c%int: Integer Part
%c%log: Natural Logarithm
%c%oct: Octal Value
%c%rnd: Random Number from (0,1)
%c%sgn: Sign
%c%sin: Sine in Degrees
%c%sqr: Square Root
%c%tan: Tangent in Degrees
echo.
set "a="
set /p "a=?"
if not defined a goto b
cls
for /f %%G in ('cscript //nologo //e:jscript "%~f0" "%a%"') do set "b=%%G"
%c%%a%=%b%
echo.
goto a
:b
pause
exit /b
@end
WScript.Echo( WScript.Arguments(0) );
- 代码已稍微重新组织李>
- 对“Eval”的调用已被删除(我不知道您要评估什么),在JS中,它是
(JS区分大小写)李>Eval
- 括号已添加到WScript.Echo(在JS中,所有函数调用都包含括号)李>
已添加到批处理结束部分,以避免执行到达JS部分exit/b
exit/b
而不是goto:EOF
。不需要我回答:-)@dbenham:谢谢,戴夫。我以前在子程序中使用exit/B
,在主文件中使用goto:EOF
,那么我应该改用WScript.Echo(Math.Arguments(0))@user3093536:正确,带有右大写和小写字母:WScript.Echo(eval(“Math.”+WScript.Arguments(0))
出于某种原因,当我将它放在批处理代码的末尾时,它仍然不起作用。+1-几乎是逐字逐句地描述我正在编写的内容:-)除了我更喜欢exit/b
而不是goto:EOF
。不需要我回答:-)@dbenham:谢谢,戴夫。我以前在子程序中使用exit/B
,在主文件中使用goto:EOF
,那么我应该改用WScript.Echo(Math.Arguments(0))@user3093536:正确,带有右大写和小写字母:WScript.Echo(eval(“Math.”+WScript.Arguments(0))代码>由于某种原因,当我把它放在b的末尾时,它仍然不起作用