Powershell和CMD提示:负值乘法问题
我编写了 powershell ps1 代码,其中包含 ($args[0] * -1)
即带有负值乘法的变量。当代码在 powershell : .\myscript.ps1
中运行时,代码会轻松通过。
在脚本的调度过程中,它不起作用,因此当我使用 Powershell.exe -ExecutionPolicy ByPass "c:\myscript.ps1" 101 3 在运行 CMD 提示符下运行它时,它引发了 ($args[0] * -1)
[负乘法] 的错误,并在 cmd 提示符下手动运行它也出现了同样的问题。
所以当时,我对代码做了一些调整,接受负值作为属性,而不是在代码中将其乘以 -1 并使其运行。
如果将来如何编写进行负值乘法并在 CMD 提示符下运行的 ps1 代码?
I wrote powershell ps1 code which has ($args[0] * -1)
i.e variable with negative value multiplication. The code just breeze through when it is run in powershell : .\myscript.ps1
.
During the scheduling of the script, it didn't work, so when I made it run in the run CMD prompt using Powershell.exe -ExecutionPolicy ByPass "c:\myscript.ps1" 101 3
, it threw the error for ($args[0] * -1)
[negative mulitplication] and manually running it in cmd prompt gave the same problem.
So at that time, I made a little tweak to code accepting the negative value as attribute instead of it being multiplied in code to -1 and made it to run.
If future how to write ps1 code which does negative value multiplication and also runs in CMD prompt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于负值输入或命令行,而在于数据类型;正如 JasonMArcher 所指出的。一个简单的类型转换就完成了所有的工作。
The problem was not with the negative value input or command line but the problem was with the data type; As it was pointed out by JasonMArcher. A simple type cast did all the trick.