首页 \ 问答 \ 执行:显示stdout“活”(Exec : display stdout “live”)

执行:显示stdout“活”(Exec : display stdout “live”)

我有这个简单的脚本:

var exec = require('child_process').exec;

exec('coffee -cw my_file.coffee', function(error, stdout, stderr) {
    console.log(stdout);
});

在那里我只需执行一个命令来编译一个咖啡脚本文件。 但是stdout不会在控制台中显示,因为命令永远不会结束(因为-w选项的咖啡)。 如果我直接从控制台执行命令,我会得到如下消息:

18:05:59 - compiled my_file.coffee

我的问题是:可以用node.js exec显示这些消息吗? 如果是的话, !

谢谢


I have this simple script :

var exec = require('child_process').exec;

exec('coffee -cw my_file.coffee', function(error, stdout, stderr) {
    console.log(stdout);
});

where I simply execute a command to compile a coffee-script file. But stdout never get displayed in the console, because the command never ends (because of the -w option of coffee). If I execute the command directly from the console I get message like this :

18:05:59 - compiled my_file.coffee

My question is : is it possible to display these messages with the node.js exec ? If yes how ? !

Thanks


原文:https://stackoverflow.com/questions/10232192
更新时间:2022-08-26 14:08

最满意答案

在最新版本的GHC中,可以使用setAllocationCounterenableAllocationLimit来设置每个线程的分配计数器和限制。 当限制被设置并且计数器达到0时,线程接收异步异常。

计数器测量分配 ,而不是现场组的大小。 例如,这个代码达到了极限,尽管它的现场设置永远不会变得很大:

{-# LANGUAGE NumDecimals #-}
module Main where

import Data.Foldable (for_)
import System.IO
import GHC.Conc (setAllocationCounter,enableAllocationLimit)

main :: IO ()
main = 
  do setAllocationCounter 2e9
     enableAllocationLimit
     let writeToHandle h =
            for_ ([1..]::[Integer])
                 (hPutStrLn h . show)
     withFile "/dev/null" WriteMode writeToHandle
     return ()

分配有点粗糙,但它仍然可以用来检测一些“失控”的计算。

Simon Marlow的这篇博客更详细地介绍了这一点。


In the latest versions of GHC, it is possible to set per-thread allocation counters and limits, using setAllocationCounter and enableAllocationLimit from GHC.Conc. When a limit is set and the counter reaches 0, the thread receives an asynchronous exception.

The counters measure allocation, and not the size of the live set. For example, this code hits the limit, despite its live set never becoming very big:

{-# LANGUAGE NumDecimals #-}
module Main where

import Data.Foldable (for_)
import System.IO
import GHC.Conc (setAllocationCounter,enableAllocationLimit)

main :: IO ()
main = 
  do setAllocationCounter 2e9
     enableAllocationLimit
     let writeToHandle h =
            for_ ([1..]::[Integer])
                 (hPutStrLn h . show)
     withFile "/dev/null" WriteMode writeToHandle
     return ()

Allocation is a bit crude as a measure, but it can still be useful to detect some "out of control" computations.

This blog post by Simon Marlow goes into more detail.

相关问答

更多
  • 单独使用monad创建一个不unsequence函数是不可能的。 原因是: 您可以使用return方便而安全地轻松创建一个monadic结构。 但是,从monadic结构中删除值并不安全。 例如,你不能从空列表中删除一个元素(即类型[a] -> a函数不安全)。 因此,我们有一个特殊的函数(即>>= ),它可以安全地从一元结构(如果存在的话)中去除一个值,对它进行处理并返回另一个安全的一元结构。 因此,从一个值创建一个monadic结构是安全的。 但是,从一元结构中删除值并不安全。 假设我们有一个函数ext ...
  • 在最新版本的GHC中,可以使用setAllocationCounter和enableAllocationLimit来设置每个线程的分配计数器和限制。 当限制被设置并且计数器达到0时,线程接收异步异常。 计数器测量分配 ,而不是现场组的大小。 例如,这个代码达到了极限,尽管它的现场设置永远不会变得很大: {-# LANGUAGE NumDecimals #-} module Main where import Data.Foldable (for_) import System.IO import GHC. ...
  • 正如Pipes.foldl的文档中所提到的,折叠是严格的。 但是,严格是用$!实现的$! 这只会迫使对WHNF进行评估 - 弱头正常形式。 WHNF足以完全评估像Int这样的简单类型,但它不足以完全评估像Maybe Int这样的更复杂的类型。 一些例子: main1 = do let a = 3 + undefined b = seq a 10 print b -- error: Exception: Prelude.undefined main2 = d ...
  • 一种简单的方法是使用-rtsopts进行编译 ghc -O2 -rtsopts Test.hs -o test 然后运行它 ./test +RTS -s 如果你需要实际的分析,你可以用-prof编译并运行-p - 这将生成一个.prof文件,然后你可以检查 (参见分析用户指南 ) one easy way is to compile with -rtsopts ghc -O2 -rtsopts Test.hs -o test and then run it with ./test +RTS -s i ...
  • 我想你可能想要这样的东西: nextStatement :: MonadError String m => Stmts -> m Stmt nextStatement (Statements s _) = return s nextStatement EmptyStmts = throwError "nextStatement EmptyStmts" 特别是Interpreter是MonadError String一个实例,所以这也可以给出类型Stmts -> Interpreter Stmt 。 你可以 ...
  • 问题在于你实际上并没有在foo里面调用 bar 。 你可以使用_ <- bar来做到这一点。 这附加"foobar"的状态: foo :: MyStateMonadT Bar -> MyStateMonadT Foo foo bar = do modify (++"foo") _ <- bar return Foo 这附加"barfoo" : foo :: MyStateMonadT Bar -> MyStateMonadT Foo foo bar = do _ <- bar modi ...
  • 类型构造函数是返回类型的类型级函数。 Maybe是一个类型构造函数,它接受一个单一的类型参数并返回一个类型,例如Maybe String , Maybe Int等。 数据构造函数用于创建特定类型的值。 对于某些类型Maybe a这些构造函数是Just和Nothing ie data Maybe a = Just a | Nothing return函数从“简单”值构造一个monadic值,例如 return 1 :: Maybe Int return "s" :: [String] 所以在Monad类的 ...
  • 对于Maybe monad bind函数( >>= )看起来像这样: (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b 所以,我们来定义一些Maybe a值: > let a = Just 1 a :: Maybe Integer 和:: a -> Maybe b函数: > let f = \x -> Just (x+1) f :: Integer -> Maybe Integer 现在我们可以使用像中缀运算符那样的绑定: > a >>= f Just 2 i ...
  • 编译而不是从ghci中运行。 在我的机器上,这使得virt从5GB到140MB; 编译版本的资源永远不会超过15MB。 一般情况下(除了极少数例外),ghci的性能特征要比编译的程序差很多。 Compile instead of running from within ghci. On my machine this took virt usage from 5GB to 140MB; res never went above about 15MB for the compiled version. In ...
  • 理解状态monad的最简单方法,我认为只是编写你自己的并且稍微玩一下。 学习这些代码,与其他人的例子一起玩,然后不时回顾一下,直到你能够从内存中写下来: -- | 'State' is just a newtype wrapper around the type @s -> (a, s)@. -- These are functions which are fed a state value (type @s@) as input, -- and produce as a pair of an @a@ (t ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)