Lets say I have a simple program : (pseudocode)
for(i=0;i<1000;i++)
{
print(i + "\n");
sleep(1);
}
Output:
0
1
2
Is there way to view this output in an editor like emacs or Vi as it changes ? The behaviour I want is like "t开发者_运维知识库ail -f" done on a file being continously written to.
This is actually built in to emacs :)
M-x auto-revert-tail-mode
From C-h f auto-revert-tail-mode :
When Tail mode is enabled, the tail of the file is constantly followed, as with the shell command `tail -f'. This means that whenever the file grows on disk (presumably because some background process is appending to it from time to time), this is reflected in the current buffer.
In emacs at least, you can open a terminal window and have it at one side. Try M-xansi-termRET. Then you can divide the screen, using the different C-x<number>.
(start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin")
⇒ #<process my-process<1>>
---------- Buffer: foo ----------
total 2
lrwxrwxrwx 1 lewis 14 Jul 22 10:12 gnuemacs --> /emacs
-rwxrwxrwx 1 lewis 19 Jul 30 21:02 lemon
Process my-process<1> finished
Process my-process finished
---------- Buffer: foo ----------
In Emacs, there is M-x shell-command, as well as various specialized modes for monitoring the output from a command. You can also run a shell inside Emacs with M-x shell. It is also not hard to have a process produce output directly into an Emacs buffer from elisp; see the documentation for start-process (C-h f start-process RET).
You can do something similar to the following using "ansi-term" and your own program (which you would substitute in place of the "top" process used in my example):
(progn
(ansi-term "/bin/sh" "top")
(goto-char (point-max))
(insert "top")
(term-send-input))
精彩评论