-1

I have stopped a job by pressing Ctrl-z. Can I resume the job with bg, yet have the output redirected to a log file instead of stdout? Doing the following:

bg > log.txt

Only writes the initial printed line (e.g. [1]+ <<job_name>> &) to the log file.

Erica
  • 103
  • This very same question has been asked among the network plenty of times, one is https://stackoverflow.com/q/593724/991073 – 把友情留在无盐 Dec 29 '20 at 03:42
  • Although SO is not unix.SE, I don't think it's worth duplicating the answers again here. (meta: what to do with cross site dups https://meta.stackexchange.com/questions/4708/what-to-do-with-cross-site-duplicates) – 把友情留在无盐 Dec 29 '20 at 03:44
  • And if someone really come up with a novel solution, they should, instead of spattering around here, consider contributing to the one canonical thread. – 把友情留在无盐 Dec 29 '20 at 03:54

1 Answers1

1

You need an external tool for that. Check for example:

reredirect

reredirect is a utility for taking an existing running program and attaching its outputs (standard output and error output) to files or another process.

or dupx

Dupx is a simple *nix utility to redirect standard output/input/error of an already running process.

Dupx is currently implemented as a simple shell script that drives GDB.