Friday 15 August 2014

time - How to use output redirection in powershell's command-measure? -



time - How to use output redirection in powershell's command-measure? -

how utilize output redirection in powershell's command-measure?

i want similar time linux, simple programme time how long programme runs

i thought work, std out doesn't redirect: measure-command {start-process python printstuff.py > output.txt -wait}

example input:

measure-command {echo hi}

example output:

days : 0 hours : 0 minutes : 0 seconds : 0 milliseconds : 0 ticks : 1318 totaldays : 1.52546296296296e-09 totalhours : 3.66111111111111e-08 totalminutes : 2.19666666666667e-06 totalseconds : 0.0001318 totalmilliseconds : 0.1318

the problem start-process doesn't write standard output. instead creates new console window , runs process standard output set console window. using redirection operator redirect stdout start-process doesn't write stdout empty file.

the solution utilize -redirectstandardoutput alternative tell start-process redirect stdout process started.

measure-command { start-process python printstuff.py -redirectstandardoutput output.txt -wait }

note if want pass options python programme have specify -argumentlist explicitly:

measure-command { start-process python -argumentlist ('printstuff.py','-opt') -redirectstandardoutput output.txt -wait }

the messiness of -argumentlist means unless need utilize start-process find easier drop , redirection works normally:

measure-command { python printstuff.py >output.txt }

note if want quote name of executable (or utilize value in variable) need utilize phone call operator (i mention wonder whether why looking @ start-process in first place):

measure-command { & "c:\python34\python" printstuff.py >output.txt }

powershell time cmd

No comments:

Post a Comment