Cannot create / dev / stdout: No such device or address

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

I simplified the problem and the 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 tried replacing /dev/stdoutwith/dev/fd/1
  • I tried changing the shell to bash ... execSync('echo ...', {shell : '/bin/bash'})

As I said, the problem above is simplified. The real script takes as a parameter the name of the file in which the 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 to execute a command using node, giving the team access to its own stdout stream?

+4
1

/dev/stdout

OSX, phantomjs, , OSX/BSD Linux /dev/stdout , , , -. , OSX /dev/stdout, Linux. , /dev/stdout, OSX. , Linux (, ).

:

Arch, , , Ubuntu.

, , execSync. , , :

var fs = require('fs');
var path = require('path');

var fdout = fs.openSync(path.join(process.cwd(), 'stdout.txt'), 'a');
var fderr = fs.openSync(path.join(process.cwd(), 'stderr.txt'), 'a');

var execSync = require('child_process').execSync,
    result = execSync('echo "hello world"', {stdio: [0,fdout,fderr] });

, , execSync. . 1 2, , stdout stderr , .

Arch 4.10.9-1-ARCH, bash 4.4.12 node v7.7.3.

+1

Source: https://habr.com/ru/post/1659161/


All Articles