I'm trying to use different terminals on Emacs. The one I'm currently trying is term.

When I execute a ps command and grep its output on Emacs, I don't get the same result as in gnome-terminal, xterm, etc...

This is what I get on Emacs:

etomort@elx306b6vv:~$ ps -ef | grep juniper
etomort  28860 28781  0 11:41 pts/2    00:00:00 grep --color=auto juniper
etomort@elx306b6vv:~$ ps -ef | grep 13109
etomort  13109     1  0 09:51 ?        00:00:04 /usr/lib/jvm/java-7-oracle/jre/bin/java -classpath /usr/lib/jvm/java-7-oracle/jre/lib/plugin.jar:/home/etomo
etomort  28876 28781  0 11:41 pts/2    00:00:00 grep --color=auto 13109

Bear in mind that greping by process id does not either include juniper on its output.

And this is what I get on gnome-terminal:

etomort@elx306b6vv:~$ ps -ef | grep juniper
etomort  13109     1  0 09:51 ?        00:00:04 /usr/lib/jvm/java-7-oracle/jre/bin/java -classpath /usr/lib/jvm/java-7-oracle/jre/lib/plugin.jar:/home/etomort/.juniper_networks/tncc.jar net.juniper.tnc.NARPlatform.linux.LinuxHttpNAR log_level 2 postRetries 6 ivehost www.myvpn.org Parameter0 interval=0;process_timeout=5;failurl=;cert_md5=1a2b3c4d5e6f7g8h9i0j1a2b3c4d5e6f7g8h9i0j;hash_key=1a2b3c4d5e6f7g8h9i0j1a2b3c4d5e6f7g8h9i0j;id=1a2b3c4d5e6f7g8h9i0j1a2b3c4d5e6f7g8h9i0j;logging=0 locale en home_dir /home/etomort user_agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0
etomort  28775 22252  0 11:40 pts/11   00:00:00 grep --color=auto juniper

So it seems that Emacs term loses characters somewhere between the ps and the pipe before the grep.

Note: I'll check in Meta Stack Exchange how to present better the output of ps, since I would prefer them truncated.

  • What does ps -ef show in emacs before you pipe it to grep? I think the ps output is truncated from the Emacs shell. Maybe ps -ef -w -w to force unlimited output width will help? – Tyler Oct 6 '15 at 20:13

I think the Emacs shell is telling ps what the column width is, and that causes ps to truncate its output. You can explicitly set the output width to unlimited by setting the -w argument twice: ps -ef -w -w. This overrides whatever settings Emacs is setting in shell mode.


As correctly guessed by Tyler, what's happening is that ps is truncating the output to the width of the terminal when it's running in Emacs Term, but not when it's running elsewhere. You can see that in the line where you grep for 13109. Note that it's ps doing the truncation, not the terminal.

The reason this happens is that Term sets the COLUMNS environment variable to the window width. Most other terminals do not do this. Your shell probably sets the COLUMNS variable, but as an shell variable only, not as an environment variable (i.e. it isn't exported). Compare:

env | grep COLUMNS

in Term and in other terminals.

The ps command uses the COLUMNS variable to determine the width of its output, even when its output isn't going to the terminal. On Linux and *BSD (including OSX), you can pass the w option twice to tell ps not to truncate lines. If COLUMNS is not in the environment, most ps implementations (including Linux) don't truncate the output if it isn't going to the terminal.

ps -efww | grep juniper


ps -ef | grep juniper

or alternatively

ps $(pgrep -f juniper)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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