javascript - process.exec() in node.js - Stack Overflow

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

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 mand 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 mand(iostat) and nonbolck mand(ls)?

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 mand 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 mand(iostat) and nonbolck mand(ls)?

Share Improve this question edited Apr 8, 2012 at 9:06 drifting asked Apr 8, 2012 at 9:04 driftingdrifting 711 gold badge2 silver badges5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745497807a4630271.html

相关推荐

  • javascript - process.exec() in node.js - Stack Overflow

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

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信