I am in the process of porting a CLI library from Ruby over to Node.js. In my code I execute several third party binaries when necessary. I am not sure how best to accomplish this in Node.
Here's an example in Ruby where I call PrinceXML to convert a file to a PDF:
cmd = system("prince -v builds/pdf/book.html -o builds/pdf/book.pdf")
What is the equivalent code in Node?
If you don't mind a dependency and want to use promises,
child-process-promise
works:installation
exec Usage
spawn usage
@hexacyanide's answer is almost a complete one. On Windows command
prince
could beprince.exe
,prince.cmd
,prince.bat
or justprince
(I'm no aware of how gems are bundled, but npm bins come with a sh script and a batch script -npm
andnpm.cmd
). If you want to write a portable script that would run on Unix and Windows, you have to spawn the right executable.Here is a simple yet portable spawn function: