当前位置: 动力学知识库 > 问答 > 编程问答 >

node.js - cannot create /dev/stdout: No such device or address

问题描述:

I'm want to run a shell command via node and capture the result of stdout. My script works fine on OSX, but not on Ubuntu.

I've simplified the problem and script to the following node script:

var execSync = require('child_process').execSync,

result = execSync('echo "hello world" >> /dev/stdout');

// Do something with result

Results in:

/bin/sh: 1: cannot create /dev/stdout: No such device or address

  • I have tried replacing /dev/stdout with /dev/fd/1
  • I have tried changing the shell to bash... execSync('echo ...', {shell : '/bin/bash'})

Like I said, the problem above is simplified. The real script accepts as a parameter the name of a file where results should be written, so I need to resolve this by providing access to the stdout stream as a file descriptor, i.e. /dev/stdout.

How can I execute a command via node, while giving the command access to its own stdout stream?

分享给朋友:
您可能感兴趣的文章:
随机阅读: