I'm trying to debug a program that generates a lot of data. But the event which I want to debug happens after a random amount of time (I cannot force it). So I would need to see the stdout and stderr in my shell and save the same output to a file for further analysis and interrupt as soon as I see what I need on my shell output.
I found the
script command on this ask Ubuntu thread but I cannot get it to work, script says :
$ script "./client -p 4242 -n test" Script started, output file is ./client -p 4242 -n test
and then exits. The file contains:
Script started on Thu Jun 26 13:51:12 2014 Script done on Thu Jun 26 13:51:12 2014
script doesn't work. The
./client file is a python script. I also tried launching it with
$ python client -p 4242 -n test but it's not working either.
I also saw on the same thread some answers with
tee and a pipe but I can't get it to output to my shell and see what is going on:
$ ./client -p 4242 -n test | tee output.log
gives me a waiting cursor without nothing happening. So
tee doesn't work.
Is there any other solution or am I doomed to wait and interrupt the program after some time and hope it went through the event I'm looking for ?
Thank you much for your help !
P.S. I'm on zshell (with oh-my-zsh), Mac OSX 10.9.3, Python 2.7.5
EDIT: I may have to mention I'm using the
multiprocessing module and the
./client script launches multiple other
Processes. Could it be for that reason ? Still I don't understand why it won't catch the
./client process output...
EDIT2: I tried the answer from Matteo below (thanks a lot for your help) and it keeps getting stranger and stranger:
If the process fails (the server is shutdown), I can see the output:
$ ./client -p 4242 -n test 2>&1 | tee output.log Process Process-1: Client # 1: Could not connect to server. Stopping. Spawner: New client # 1 started... Done. $
but if it looks like it's running, I see nothing:
$ ./client -p 4242 -n test 2>&1 | tee output.log ^C [voluntary interrupt after a lot of waiting] $ cat output.log $
In the log above (where it fails), you can see that the new process prints before the main one (
Spawner) even though it started after it. So it looks like some really strange output magic.