4

The documentation to vim's system function says this about the second argument:

When {input} is given, this string is written to a file and passed as stdin to the command.

What I understood from that was that if your system call looked like this:

call system('node something.js --file', 'here is some text')

The command executed would look like this:

node something.js --file some/temp/file

and some/temp/file would have the text here is some text as its contents. To test this, I ran the vim command (the second line is the result):

:echo system('cat', 'here is some text')
here is some text

Ok, that looks right. A second test:

:echo system('echo', 'here is some text')
<blank line>

Instead of getting some temporary file's name, I got a blank line. Moreover, when I print process.argv in my node.js script, I just get ['node', 'path/to/something.js', '--file'].

What am I missing about how the {input} argument is to be used? How come it seems to work for cat, but not echo or my own script?

benekastah
  • 5,651
  • 1
  • 35
  • 50

1 Answers1

4

You've got it wrong; the command executed is not

node something.js --file some/temp/file

but rather

echo "some/temp/file" | node something.js --file

or better

node something.js --file < some/temp/file

If you want text passed as arguments, just append this to the first argument of system() (properly escaped through shellescape()).

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324