Sample Header Ad - 728x90

Redirect spawned process to tempfile with the pid in its filename

1 vote
1 answer
63 views
Suppose myprogram is spawned through the terminal (bash) and gets pid of 1234 (different everytime). I want to redirect, both stdout and stderr, to a tempfile named abc-$PID (if the PID is 1234, use tempfile abc-1234. The code looks like this now:
myprogram > /tmp/abc-$! 2>&1
it doesn't work Please help.
Asked by sudoer (65 rep)
Oct 29, 2022, 12:28 AM
Last activity: Oct 29, 2022, 01:11 AM