drifting
drifting

Reputation: 71

process.exec() in node.js

Here is the code i wrote,when i execute the code,the terminal didn't output anything and the program is blocked

var util=require('util')
var exec=require('child_process').exec;
exec('iostat 5',function(err,stdout,stderr){
    util.puts("hello")
    util.puts(stdout)
})

If i change the exec command like this: it works and outputs the file list

var util=require('util')
var exec=require('child_process').exec;
exec('ls -al',function(err,stdout,stderr){
    util.puts("hello")
    util.puts(stdout)
})

is there any diffent between a block command(iostat) and nonbolck command(ls)?

Upvotes: 1

Views: 10606

Answers (1)

Andy Ray
Andy Ray

Reputation: 32066

iostat 5 loops forever every 5 seconds and never terminates, so your exec callback will never be called. Instead you could call iostat from a setInterval call, or just remove the 5 if you only need it once.

Upvotes: 2

Related Questions