3

I'm stuck trying to print a custom command execution time. If I try to do something like this:

echo %time% & START "TestAgente" /W systeminfo  & echo %time%

I got same begin and end time:

enter image description here

I have tried with some combinations playing with delayed-expansion, but I think it fails (I guess) because in running 3 commands in a line instead of batch file.

Does anyone done something like this (without PowerShell). It has to be a single command line that someone could copy, paste and execute.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Carol
  • 603
  • 2
  • 9
  • 24
  • 1
    [duplicate](https://stackoverflow.com/questions/673523/how-do-i-measure-execution-time-of-a-command-on-the-windows-command-line) - even with the correct one-line-syntax. – Stephan Oct 05 '18 at 16:23
  • I read that before posting, but I couldn't find a proper answer for my problem, sorry. Could you please tell me what's the proper way to fix it in a single line without using power shell? – Carol Oct 05 '18 at 17:08
  • Yes, answer was there. Sorry for duplicate. – Carol Oct 05 '18 at 17:15
  • 1
    `cmd /v:on /c "echo !TIME! & timeout 5 & echo !TIME!"` - by Nathan Herring. – Stephan Oct 05 '18 at 17:17
  • Possible duplicate of [How do I measure execution time of a command on the Windows command line?](https://stackoverflow.com/questions/673523/how-do-i-measure-execution-time-of-a-command-on-the-windows-command-line) – Stephan Oct 06 '18 at 15:46

1 Answers1

1

Like @Stephan said, the right way was in that post, and it worked!!

cmd /v:on /c "echo !time! & START "TestAgente" /W systeminfo & echo !time!"
Carol
  • 603
  • 2
  • 9
  • 24
  • 2
    Note: `Start` opens another `cmd` instance, which needs time, which gives you (slightly) wrong results. More accurate: `cmd /v:on /c "echo !time! & systeminfo & echo !time!"` – Stephan Oct 05 '18 at 17:29