DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+1 vote

In linux when I start a job in background with & at the end of the command I get the output in the terminal. Is there a way to always send the output from background jobs to a log file with the name of the executable and it's location? For example executable & would store the output in executable.log which would be located in the same place as executable.

by
retagged by

1 Answer

+1 vote
 
Best answer

When you start a new job in background, the file descriptors don't change. That's why you see the output on the terminal. Indeed, you can even start 2 jobs and see the output overlapping:

$ ping wotas.net &
$ ping freepo.st &

You can redirect stdout the usual way:

$ ping wotas.net > ping.log &

But I've never seen a built-in way for redirecting stdout to a log file with the same name and location of the program. It doesn't sound like a good design. It sounds more like a particular scenario that you'll have to script your way to, perhaps like one of these:

$ executable > $(realpath executable).log &
$ executable > $(which executable).log &
by
selected by
Contributions licensed under CC0
...