Hi,I want to be able to run arbitrary shell commands within my node program.One example is this command:openssl rand -hex 12 Which outputs a random hex string, but it has a trailing new line at the end, which I do not want. If I was using a bash script, I would just do:echo -n $(openssl rand -hex 12) Where the -n option removes the trailing new line. However, when using node's child process, I seem to run into 2 problems:I don't think node child process is capable of command substitution like I did with $(...)Even if I don't use command substitution, the -n option is not working, and it literally prints out -n followed by my output.I have tried both child_process spawn, and exec, and I tried many different options for spawn (such as detached, stdio: inherit, shell: true, etc), but I have not found options that allow me to use the -n option.If command substitution does not work, that's fine by me, I'm more concerned with how to get the -n option to work. Any suggestions? Is this even possible?
Submitted March 04, 2019 at 04:00AM by ns_helloworld
No comments:
Post a Comment