Powershell and CMD prompt : Negative value multiplication problem
I wrote powershell ps1 code which has ($args[0] * -1)
i.e variable with negative value multiplication. T开发者_如何转开发he 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?
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.
精彩评论