1

the linux command code time <command> | tail -n2, I expect to extract the line of sys time and use time, however,I get this as follows:

time picat slater-6_sat ver2 "0"

the Output is :

winner = 4 with the least cost = 0

CPU time 0.0 seconds.

success

real    0m0.054s
user    0m0.035s
sys     0m0.019s

while when I only input the picat slater-6_sat ver2 "0"

the Output is:

winner = 4 with the least cost = 0

CPU time 0.0 seconds.

success

I expect input time picat slater-6_sat ver2 "0" | tail -n2 ,

the Output is :

user    0m0.035s
sys     0m0.019s

however, the truth is :


success

real    0m0.054s
user    0m0.035s
sys     0m0.019s

I guess the reason is the processor think as time ,so treat picat slater-6_sat ver2 "0"| tail -n2 as the command

how can I solve the problem?

1 Answers1

0

You can try something like this:

(time picat slater-6_sat ver2 "0") > output.txt 2>&1 && tail -2 output.txt

See a similar answer here: Output time to file with unix "time" command, but leave output of command to console

Here's a sample python file:

from time import sleep
for x in range(0,10):
    sleep(0.4)
    print(x)

Now run the file like so:

$ (time python3 test.py) > output.txt 2>&1 && tail -2 output.txt

user    0m0.026s
sys 0m0.004s

Additional resources:

zedfoxus
  • 35,121
  • 5
  • 64
  • 63
  • @LibertyAndHappy Absolutely. If you found this answer helpful, I’ll recommend that you put closure to your question by marking it accepted, or wait for other answers and then choose one that’s most acceptable. There’s a check mark by the answer that you can click. Others can then see that this is a solved question and use the question/answer to learn. – zedfoxus May 09 '22 at 02:50
  • 1
    Done,and thanks for teaching me this! – LibertyAndHappy May 09 '22 at 03:04