I want to use node.js to spawn echo $(python --version), if I put this into my terminal it works no problem, I get something like
Python 2.7.12
But if I use the following code:
var spawn = require('child_process').spawn
var child = spawn('echo', ['$(python --version)'])
child.stdout.on('data', function(b){
console.log(b.toString())
})
I just get the string literal echo'ed back to me:
$(python --version)
How to I escape the argument to spawn properly so I get the correct output.
Edit: I specifically want to use spawn, and echo, I would like to know if there is a solution to properly escape the spawn argument...
$()is a bash operator, and child_process is using sh instead of bash. See stackoverflow.com/questions/32952410/… for setting your shell while using child_process.echo $(python --version), in a shell, the echo is pretty much useless. Sincepython --versiondoesn't output anything to stdout, you are just runningpython --versionand then runningechowith no arguments. It is the equivalent of doing$(python --version); echo, which means the echo just prints a newline character.