从IDL脚本将参数传递给shell脚本

时间:2016-07-31 19:58:35

标签: shell spawn idl-programming-language

我正在尝试编写调用的IDL脚本,例如a.pro。在这个脚本的最后,我想执行shell脚本b。我正在尝试使用spawn命令。但是我还需要从IDL脚本向这个shell脚本传递一些参数(变量值)。我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:3)

您发送给SPAWN的命令只是一个字符串;以你喜欢的方式创建字符串。我更喜欢使用C风格的格式代码:

filename = 'output.log'
n_lines = 50
cmd = string(n_lines, filename, format='(%"tail -%d %s")')
; cmd = 'tail -50 output.log'
spawn, cmd, output

答案 1 :(得分:1)

有两种方法可以调用SPAWN来完成您想要的任务:

直接调用脚本b

spawn, ['b', arg1, arg2], /noshell

优点:

  • 更快,因为它没有创建bash的新实例。
  • 更安全,因为你不必逃避或引用争论。

格式为bash终端字符串:

script_path = 'b'
cmd = strjoin([script_path, arg1, arg2], ' ')
spawn, cmd

优点:

  • 有时会更简单,因为您可以使用以前从bash查看的格式。

在大多数情况下,您应该直接使用spawn, /noshell调用脚本和其他程序(除了IDL),因为速度提升很大,安全性可能相当高。

相关问题