最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论