Answer the question
In order to leave comments, you need to log in
How to accept the output of a windows command called from node.js?
Let's create an index.js
file like this:
require('child_process').exec('dir', function(err, outstr){
console.log(outstr);
});
??? ? ?????? U ????? ????? USBSTICK
?????? ????? ??: 467B-0CBE
???????? ????? U:\Fido\Soft\_Sources\node
24.11.2011 15:12 <DIR> .
24.11.2011 15:12 <DIR> ..
25.11.2011 09:36 522 index.js
1 ???? 522 ????
2 ????? 17?412?767?744 ???? ??????
var fs = require('fs'); // file system
require('child_process').exec('dir', function(err, outstr){
fs.createWriteStream('testfile.txt', {
flags: 'w',
encoding: 'binary'
}).write(outstr);
});
U:\Fido\Soft\_Sources\node>dir
Том в устройстве U имеет метку USBSTICK
Серийный номер тома: 467B-0CBE
Содержимое папки U:\Fido\Soft\_Sources\node
24.11.2011 15:12 <DIR> .
24.11.2011 15:12 <DIR> ..
25.11.2011 09:37 522 index.js
1 файлов 522 байт
2 папок 17 412 767 744 байт свободно
Answer the question
In order to leave comments, you need to log in
There is a chcp command that changes the terminal encoding in Windows. In general, of course, it's better not to bathe, but to use good things in good server OS.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question