1

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)?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.