0

I have below code in my batch file

echo >"%temp%\%~n0.vbs" s=DateAdd("d",0,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^&  right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "mydate=%%a"
set dd=%mydate:~6,2%
set mm=%mydate:~4,2%
 set yyyy=%mydate:~0,4%
 set mytime=%time::=%
 set mytime=%mytime: =0%
 echo %dd%%mm%%yyyy%%mytime:~0,4%
 del "%temp%\%~n0.vbs" /Q

This code works ok i run batch file manually. But this batch file is run by Jenkins while deploying code and Jenkins runs it from c:\windows\system32 So i get weiered output like tInpu0815

How to fix this?

James
  • 1,827
  • 5
  • 39
  • 69
  • 2
    James, in your [previous question](https://stackoverflow.com/q/58092146) you were given a link in the comments to [this answer](https://stackoverflow.com/a/19799236), which had an array of methods for getting date stamps. Which of those have you tried, in finding a solution to your issue? Also have you tried continuing with the VBScript, but not writing it out to an external file? BTW run `del /?` and read its output, you'll note that the `/Q` option is unnecessary, because there's no wildcard! You've also added needlessly added a leading space character to the first line of your VBScript. – Compo Sep 26 '19 at 09:29
  • @Compo can you let me know why its giving wrong output – James Sep 26 '19 at 12:42
  • @Compo i am using vbscript as written in code. Only issue is that its not working correctly when Jenkins executes it batch file from Windows/system32 – James Sep 26 '19 at 12:52
  • @Compo now i tried to echo each of variable and saw that variable dd is blank, variable mm is t, variable yyyy is Inpu, variable mytime is 145524.25 , so total output it prints is tInpu1455. Time here now is 14.55 – James Sep 26 '19 at 12:58
  • I'm going to assume that there's an error message being output, try running `CScript //NoLogo "%TEMP%\%~n0.vbs"` as your new line `3`, remove lines `4`-`9` and add a `Pause` to the end to see what is being returned. You could then post that if you don't understand what it means. – Compo Sep 26 '19 at 13:10
  • i get error when i wrote as you told Input Error: Can not find script file "C:\Users\appveyor\AppData\Local\Temp\1\RunTestsWithReporting.vbs". – James Sep 27 '19 at 05:53
  • @Mofi sorry it works :).. can you post it as answer? – James Sep 27 '19 at 08:43
  • 1
    No, because you were already provided with the information in your last question and again in my opening comment here. It is a duplicate as the question has been effectively asked before and the solution given. Also the error message you've posted is does not match the code, unless you've changed the code without telling us, or have modified the value of your system variable `%TEMP%`. – Compo Sep 27 '19 at 09:05

0 Answers0