简体   繁体   中英

Is there a way to send a running terminal command to the background AND change the output to pipe to a log file?

Sometimes when I run a log running terminal command, I'd like to send it to the background and start doing something else in the same shell. I can do this with Ctrl+Z and bg .

However, the annoying effect this has is that it keeps showing output of the above command intermittently. Instead, when I move the process to the background, I'd also like to change where the output goes as well.

Importantly, I'm asking how to do this for an already-running command - I know that do this from scratch I could do something like command arg1 arg2 &> ~/logs/output.log & .

I have used Reptyr for this in the past.

It does have its limitations (especially with GUIs / Curses) but has worked well for me.

https://linux.die.net/man/1/reptyr

You can either start a Screen session and use reptyr to grab your running process into the screen session. Or start a new bash session which is outputting to a file and then grab the running process with reptyr.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM