|
Answer» I know this sounds relatively simple but it turns out it isn’t for me.
Here is one of the command line commands I have tried.
c:\timeit xcopy a.txt b.txt > test.txt
I had expected the following to be in the output file.
(BEGIN)
Version Number: Windows NT 5.1 (Build 2600) Exit Time: 2:23 pm, Wednesday, January 30 2008 Elapsed Time: 0:00:10.860 Process Time: 0:00:00.046 System Calls: 227519 Context Switches: 109458 Page Faults: 4909 Bytes Read: 103812 Bytes Written: 156129 Bytes Other: 298850
(END)
Instead I have this.
(BEGIN)
C:a.txt 1 File(s) copied
(END)
Apparently I am capturing the output of the xcopy command and not timeit. I have tried various combinations of pipes and redirections to no avail. Any ideas?
try this > test.txt c:\timeit xcopy a.txt b.txt
if that doesnt work, do this
> test.txt cmd c:\timeit xcopy a.txt b.txt which opens up a new command shell and executes your command within that, the WHOLE lot being redirected to a file ... it might be simpler if you put the SE commands into a .bat file c:\timeit xcopy a.txt b.txt
call it mybatch.bat, then do this > test.txt cmd mybatch
Graham > test.txt c:\timeit xcopy a.txt b.txt
The text file still contains the output of xcopy and not timeit.
> test.txt cmd c:\timeit xcopy a.txt b.txt
Adding "cmd" hangs it.
> test.txt cmd mybatch
Hangs. It appears any lines that include "cmd" hang for some reason. Without the "cmd", it runs, but again it captures the xcopy output and not the timeit output.
It is as if the output of timeit is sent directly to the screen rather than letting the shell handle it.
Using timeit.exe was my second attempt. My first was to use "time /t > test.txt" on a line before the xcopy command and "time /t >> test.txt" after the xcopy command to obtain the start and finish time, but unlike my memory of the "time" command in earlier DOS implementations, the maximum resolution is in minutes, e.g. 1:23 PM. I need a resolution in at least whole seconds but to a tenth would be better e.g. 1:23:45 PM or 1:23:45.6 PM It's very possible that timeit is not using the STDOUT device.
Code: [Select]echo. | time > time.txt xcopy echo. | time >> time.txt Precision is .01 seconds
The output isn't very pretty since it echos the request for a new time. but it works and that is all that matters.
I assumed I needed the "/t" or it would hang, which as I recall it did with just "time > test.txt" but you have proved that doesn't have to be the case in all instances.
Thanks for your help. This worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.
c:\timeit xcopy a.txt b.txt 2> test.tmp
~~~~~ rog
C:\test>timeit.exe "sleep 60"
Version Number: Windows NT 6.1 (Build 7600) Exit Time: 5:15 pm, Friday, May 21 2010 Elapsed Time: 0:01:00.013 Process Time: 0:00:00.000 System Calls: 12804 Context Switches: 10368 Page Faults: 1342 Bytes Read: 16679 Bytes Written: 9790 Bytes Other: 9484
C:\test>
_________________________
C:\test>timeit.exe sleep 60 2> test.txt
C:\test>type test.txt
Version Number: Windows NT 6.1 (Build 7600) Exit Time: 5:33 pm, Friday, May 21 2010 Elapsed Time: 0:01:00.013 Process Time: 0:00:00.000 System Calls: 14938 Context Switches: 11090 Page Faults: 1100 Bytes Read: 16715 Bytes Written: 512 Bytes Other: 5692
C:\test>why did rogs revive a thread which is nearly two and a half years old?Quote from: rogs on May 21, 2010, 01:40:04 PM This worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.
c:\timeit xcopy a.txt b.txt 2> test.tmp
rog
Rog,
Thanks for reviving good questions and solutions from the archive. Many new members and readers have not used timeit.exe before now.
____________________
p.s. Some ideas are always relevant. We still read and agree with what Jesus said many years ago.Quote from: rogs on May 21, 2010, 01:40:04 PMThis worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.
c:\timeit xcopy a.txt b.txt 2> test.tmp
By the way, I know "2>" redirection works in this case. But I thought "2>" was for standard error? Redirection works nearly the same for Unix. I'm not perfectly CLEAR on how and when to use the different symbols of redirection.
Please enlighten.
Thanksstreams:
1. STDOUT
> on its own is the short way of redirecting stream 1
these are equivalent:
command >file.txt command 1>file.txt
2 STDERR
command 2>file.txt
to combine both streams
command>file.txt 2>&1
so to get both the standard output of DIR (the file listing) and also any error message ("file not found")
dir >file.txt 2&>1
Quote from: rogs on May 21, 2010, 01:40:04 PMThis worked for me... Seems that the timeit.exe uses the normal error level 2 to output it's results.
c:\timeit xcopy a.txt b.txt 2> test.tmp
There must a bug with timeit.exe since timeit.exe requires "2>" to redirect regular output ( standard Out ) to a file. For other programs only ">" is required.
Quote from: marvinengland on May 22, 2010, 06:49:54 PMThere must a bug with timeit.exe since timeit.exe requires "2>" to redirect regular output ( standard Out ) to a file. For other programs only ">" is required.
Not a bug necessarily; some programs are deliberately designed that way. I expect in this case it is done so that the output of the program to be timed can be kept separate from the output of timeit. Or some such reason.
|