If you don’t like terminal multiplexers which solve the need to manage much of what you are trying to address - tmux / screen etc. perhaps check out mosh - https://github.com/mobile-shell/mosh

To the question, perhaps this is a viable scenario to address in the shell natively -

Example - use a combination of redirection and process management tools like `disown`.

1. **Start the command in the background and redirect stdout to a file:**

```bash

command > output.txt 2>&1 &

```

2. **Disown the background process (optional):**

```bash

disown

```

If you need to alter stdout to a file after the task has already been backgrounded, you would generally need to use tools like `nohup`, `screen`, or `tmux`.

OR using `exec` within a shell:

1. **Find the PID of the background process:**

```bash

jobs -l

```

2. **Use `exec` to redirect stdout of that PID:**

```bash

exec 1> output.txt

```

YMMV / not always straightforward and might require additional handling depending on the specific task and shell environment you are using.

You could also send std out to dev null on command execution in shell and then send a sigstop to the PID and fg it, bring std out back to your running shell.

Reply to this note

Please Login to reply.

Discussion

No replies yet.