Skip to content

stdout event ? #5

Open
Open

Description

@smolleyes

hi

if i want to use something like thsi for exemple

pv file.tgz | tar xzf - -C target_directory

wich return in live

1.16MB 0:00:20 [6.06MB/s] [==================> ] 55% ETA 0:00:37

how can i yield a spawn and get the live output from stdout or stderr like normal spawn ?

thanks

Activity

  1. smolleyes commented on Apr 27, 2016

    @smolleyes
    Author

    i tried

    var co = require('co')
    var spawn = require('co-child-process')
    var fs = require('fs')
    
    co(function* () {
      var t = yield unzip()
    })
    
    function * unzip() {
       var stream = fs.createReadStream("/home/sylvain/Documents/imgtmp/photos.zip")
       var out = yield spawn('pv',['-','|','unzip-stream','/tmp']).pump(stream)
    }
    

    where unzip stream is an alias :
    alias unzip-stream="python -c \"import zipfile,sys,StringIO;zipfile.ZipFile(StringIO.StringIO(sys.stdin.read())).extractall(sys.argv[1] if len(sys.argv) == 2 else '.')\""

    running this command from command line works very well :

    pv /home/sylvain/Documents/imgtmp/photos.zip | unzip-stream /tmp/test

    but from the node code i have ...

    /tmp/node_modules/co-child-process/lib/index.js:53
        function onoutdata(chunk) {
                          ^
    
    RangeError: Invalid string length
        at Socket.onoutdata (/tmp/node_modules/co-child-process/lib/index.js:53:23)
        at emitOne (events.js:90:13)
        at Socket.emit (events.js:182:7)
        at readableAddChunk (_stream_readable.js:153:18)
        at Socket.Readable.push (_stream_readable.js:111:10)
        at Pipe.onread (net.js:529:20)
    
    
  2. NickHeiner commented on Apr 27, 2016

    @NickHeiner
    Contributor

    I'm not sure what the problem is, and I don't have a whole lot of time to investigate. You may be better off just using child_process directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions