Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We're designing a shell in the browser that will stream everything that shell outputs. stdout, stderr, anything.

however, just as this little example would demonstrate to you,

git clone https://github.com/joyent/node.git >./git.out 
cat ./git.out

most of the output is not given to ./git.out. here is little video, if you want to see what's happening http://screencast.com/t/7zTdPfq7Pr7

We need commands like 'top','git' to work, any ideas how to get them ?

(outputting into a file is for illustration purposes only, we will stream every line of output to another system, we know for top it wouldn't make sense but I hope my point is clear enough for the ones who can provide insight. thanks.)

share|improve this question
    
Are you looking for something like this from Attachmate. attachmate.com/products/terminal+emulation/refweb/refweb.htm –  Nunya Jul 3 '11 at 17:57
    
@nunya yes, but this is the last thing we'd want to do.. Requirements Reflection for the Web Clients: Web browser enabled for Java 1.5+ –  Devrim Jul 3 '11 at 18:39
1  
Something like script? –  glenn jackman Jul 3 '11 at 19:07
add comment

1 Answer

Most programs have two outputs: stdout and stderr. stdout is where the "main" information goes. stderr is used for, well, errors. It's also used for various non-important output, and also things like user prompts sometimes.

To capture all of it, you need to redirect stderr to stdout.

somecmd arg1 arg2 arg3 >somefile 2>&1

Or to capture stderr to a seperate file:

somecmd arg1 arg2 arg3 >stdout.txt 2>stderr.txt

Be aware that it IS possible for a program to use other outputs than stdout / stderr. It can determine your console and basically "force" output there. However this is extremely uncommon, and the above will work in 99% of situations.

One thing to keep in mind if you redirect both stdout and stderr to the same file is that stdout and stderr buffer differently, so it won't look the same in a log file as it will on the screen (lines will be out of order). Also, for your specific instance, your output is going to look like garbage. git does a lot of terminal manipulation (for the progress indicator) and in a log file it's going to look pretty awful.

EDIT

From man git-clone:

--progress
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal

share|improve this answer
    
hey chris - unfortunately this is not capturing that 'garbage' we're after. It suppresses all the output (assuming it's a good thing) but log file has no garbage in it which is exactly what we want. Try: git clone https://github.com/joyent/node.git >somefile 2>&1 your other version is the same. –  Devrim Jul 3 '11 at 17:30
    
Ah yes, I'm getting that behavior too. I believe git is testing to see if stderr is a terminal. To force it, I just used --progress and it worked fine. –  Chris Jul 3 '11 at 17:52
    
awesome! thanks.. is there a way to have this behavior for everything else ? (problem solved for git, but there are many other bash stuff that do the same) –  Devrim Jul 3 '11 at 18:34
    
@Devrim: It honestly depends on the program. Some do like git here, some may even not let you disable that behavior. Others use ncurses which is whole other beast by itself. You'll have to do your homework on each problematic program. –  Chris Jul 3 '11 at 18:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.