gnuplot如果未通过,如何将变量设置为标准输入

问题描述

我有一个gnuplot脚本(plot.script),其调用方式类似于

C:> ffmpeg -i '.\my_awesome_audio_file.wav' -filter_complex aformat=channel_layouts=mono -acodec pcm_s16le -ar 4000 -f data - | gnuplot -e "fileout='plot';fileformat='png';wid=500;" .\plot.script        

现在,如果不将其作为参数传递,我想将filein变量默认为stdin。这是因为我希望能够使用ffmpeg数据生成的1-liner命令以及逐步过程来调用此脚本

我的想法是使用

if(!exists('filein')){
filein = '-';
}

但这会抛出 warning: Skipping data file with no valid points

如果我打印变量数据文件,我得到了-(我期望像stdin这样的东西)。

这是plot.script脚本:


if(!exists('filein')){
    filein = '-';
    }

if (!exists("hei")){
    hei = 4444;
    }
if (!exists("wid")){
    wid = 5555;
    }
if(!exists("fileformat")){
     fileformat = 'png';
     }
if(!exists("fileout")){
     fileout = 'risultato';
   }
   
fileout = fileout . '.' . fileformat;
   
if(!exists("dataformat")){
    dataformat = '%int16';
    }
if(fileformat eq 'png'){
  set terminal png transparent size larghezza,altezza;
  
  }else{
  set terminal fileformat size wid,hei;
  }
  set output fileout;
  unset key;
  unset tics;
  unset border;
  set lmargin 0;
  set rmargin 0;
  set tmargin 0;
  set bmargin 0;


print filein;
plot filein binary filetype=bin format=dataformat endian=little array=1:0 with lines linecolor "0x009900";

但我也想按命令调用此命令: 生成数据文件:

c:> ffmpeg -i '.\my_awesome_audio_file.wav' -filter_complex aformat=channel_layouts=mono -acodec pcm_s16le -ar 4000 -f data audio.dat

绘制数据:

c:> gnuplot -e "filein='audio.dat';fileout='plot';fileformat='png';wid=500;" .\plot.script

解决方法

可能有很多方法可以解决这个问题,但是我的建议是从调用它的shell命令打开的管道中获取gnuplot图。然后由外壳通过现有文件中的cat或将流定向到该管道来填充该管道。这是文档中的相关部分(请参见help pipes

 On systems with an fdopen() function,data can be read from an arbitrary file
 descriptor attached to either a file or pipe.  To read from file descriptor
 `n` use `'<&n'`.  This allows you to easily pipe in several data files in a
 single call from a POSIX shell:

       $ gnuplot -p -e "plot '<&3','<&4'" 3<data-3 4<data-4
       $ ./gnuplot 5< <(myprogram -with -options)
       gnuplot> plot '<&5'

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...