4

In Perl you can do something like

perl -E'my $date = `date`; say $date'

This is a terse way to run a command synchronously and set the variable to STDOUT. In Node, how can I quickly run a command to capture the stdout?

ThisSuitIsBlackNot
  • 23,492
  • 9
  • 63
  • 110
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468

1 Answers1

5

Try using .execSync with an explicit encoding.. In the shortest form (with whitespace),

var date = require('child_process').execSync('date', {encoding: 'utf8'} )
console.log(date);
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468