1

I'm trying to write IDL script called, for example, a.pro. In the end of this script I want to execute shell script b. I'm trying to do it using spawn command. But I also need to pass some parameters (variables values) to this shell script from IDL script. How can I do that?

asynchronos
  • 583
  • 2
  • 14

2 Answers2

3

The command you send to SPAWN is just a string; create the string any way you like. I prefer using C-style format codes:

filename = 'output.log'
n_lines = 50
cmd = string(n_lines, filename, format='(%"tail -%d %s")')
; cmd = 'tail -50 output.log'
spawn, cmd, output
mgalloy
  • 2,356
  • 1
  • 12
  • 10
1

There are two ways to call SPAWN to accomplish what you want:


Call the script, b, directly:

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

Advantages:

  • Faster, because it doesn't create a new instance of bash.
  • Safer, because you don't have to escape or quote the arguments.

Format as a bash terminal string:

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

Advantages:

  • Sometimes easier, because you can just use the format you're used to seeing from bash.

In most instances, you should call scripts and other programs (besides IDL) directly with spawn, /noshell, because the speed gains are substantial, and the safety may be considerable.

Pi Marillion
  • 4,465
  • 1
  • 19
  • 20