在谷歌浏览器中打开标准流

时间:2012-01-28 13:25:41

标签: linux google-chrome

我有一个程序可以创建一个html文件作为标准输出。要在vim中查看它,我只需要:

$ foo2html foo | vim -

将使用stdin读入启动vim进行查看。一旦我关闭vim,命令就会返回。

是否有一些命令行开关的组合会让google-chrome这样做?

2 个答案:

答案 0 :(得分:3)

不,我不这么认为。但你可以通过临时文件来代替:

TEMPFILE=`tempfile` && foo2html foo > $TEMPFILE && google-chrome $TEMPFILE

答案 1 :(得分:1)

只需使用data URIs

# google-chrome
echo '<h1>hello</h1>' | google-chrome "data:text/html;base64,$(base64 -w 0 <&0)"

# firefox
echo '<h1>hello</h1>' | firefox "data:text/html;base64,$(base64 -w 0 <&0)"

# chromium
echo '<h1>hello</h1>' | chromium "data:text/html;base64,$(base64 -w 0 <&0)"

# opera
echo '<h1>hello</h1>' | opera "data:text/html;base64,$(base64 -w 0 <&0)"

# Default browser (in debian systems)
echo '<h1>hello</h1>' | x-www-browser "data:text/html;base64,$(base64 -w 0 <&0)"

在诸如debian之类的系统上,可从coreutils获得base64命令

sudo apt-get install coreutils

如果您未安装coreutils或无法安装新软件包,则可以使用python模块base64(几乎所有发行版都具有python)

echo '<h1>hello</h1>' | google-chrome "data:text/html;base64,$(python -mbase64 <&0)"