如何不借助中间文件将Octave图像保存至stdout?
如何直接将MATLAB/Octave图像以SVG格式输出至stdout(无需中间文件)
你尝试通过以下代码将当前图像以SVG格式保存到标准输出:
saveas(gcf, "/dev/stdout", "svg");
但遇到错误:
error: print: cannot open file /dev/stdout.svg for writing error: called from print at line 447 column 7 saveas at line 150 column 5
原因是saveas会自动为目标文件名添加对应格式的后缀,导致实际尝试写入/dev/stdout.svg而非/dev/stdout。当前你用临时文件中转的方式可以实现需求,但可以直接用print命令绕过这个限制,无需中间文件:
print(gcf, '-dsvg', '-noui', '/dev/stdout');
说明:
-dsvg:明确指定输出格式为SVG,无需依赖文件名后缀推断-noui:可选参数,用于排除UI元素(如工具栏),仅输出图像内容/dev/stdout:直接指定标准输出作为目标,print不会自动添加后缀,因此可以正确写入
执行上述代码后,SVG内容会直接输出到stdout,无需创建临时文件再读取删除。
内容的提问来源于stack exchange,提问作者user1095108
相关产品推荐
相关产品推荐

