I would like to start a subprocess in JavaScript for Automation (JXA) and send a string to that subprocess's stdin which might include newlines, shell metas, etc. Previous AppleScript approaches for this used bash's <<<
operator, string concatenation, and quoted form of
the string. If there was a JavaScript equivalent of quoted form of
that I could trust to get all of the edge cases, I could use the same approach; I'm investigating regex methods toward that end.
However, I thought since we have access to unistd.h
from JXA, why not try to just call $.pipe
, $.fork
, and $.execlp
directly? $.pipe
looks like it should take an array of 2 integers as its parameter, but none of the things that I have tried worked:
ObjC.import('unistd')
$.pipe() // Error: incorrect number of arguments
$.pipe([]) // segfault
$.pipe([3,4]) // segfault
$.pipe([$(), $()]) // segfault
var a = $(), b=$()
$.pipe([a,b]) // segfault
$.pipe($([a,b])) // NSException without a terribly helpful backtrace
$.pipe($([$(3), $(4)])) // segfault
var ref = Ref('int[2]')
$.pipe(ref)
ref[0] // 4, which is close!
Any suggestions?
NSTask.launch
. Any workarounds? – Nimesh