Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Background command 'bg' problem

Background command 'bg' problem
Thread Tools
Junior Member
Join Date: Nov 2005
Location: Montreal, Canada
Status: Offline
Reply With Quote
Feb 12, 2006, 07:55 PM
 
When I use the BG command to let a process continue running in the background, it continues to output the data to my screen.
This means that while typing some other commands, I'll still get data outputted underneath. IT's really annoying and shouldn't happen. Does this make sense?
     
Junior Member
Join Date: Nov 2001
Location: Seattle
Status: Offline
Reply With Quote
Feb 12, 2006, 10:27 PM
 
Yes, this is exactly what happens. The typical solution is to send the output of the program to a file when you run it. Example:

./myprogram > somefile &

(The & runs the command in the background from the start, so you don't have to suspend it and restart it in the background with bg). Note that this sends only the standard output (stdout) of myprogram to somefile; if myprogram also writes error/diagnostic information (to stderr) then you need to capture this as well, via

./myprogram >& somefile &

If you wish to see how myprogram is progressing at any point, just "cat somefile", or do "tail -f somefile" to see everything being output in realtime. Of course, you can Ctrl-C the tail command if you want your shell back, and myprogram continues to run in the background.

Note that I'm describing commands for tcsh; if you're shell is bash, then I believe the redirect is slightly different for capturing stderr as well as stdout. Perhaps something like (not quite so sure on this one; I don't use bash much):

./myprogram &> somefile &

Do "man tcsh" or "man bash" for fancier uses of redirecting; if you don't want the output at all you can send it to /dev/null; you can also split the stderr and stdout streams to two separate files, and all that jazz, should you so desire.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:34 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2