Programming/node.js2018. 9. 6. 18:45

js 라고는 해도 서버사이드로 확장되면서 서버에서는 당연히(?) 있어야 할 exec()가 추가되었다.

아무튼 exec()로 나오는 결과를 받아서 먼가 처리하는 것 까지는 해봐야 할 듯..


[링크 : https://blog.outsider.ne.kr/551]

[링크 : https://mylko72.gitbooks.io/node-js/content/chapter9/chapter9_2.html]

[링크 : https://nodejs.org/api/child_process.html]


+

2018.09.07

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

child;


child = exec("dir", function(error, stdout, stderr)

{

console.log(stdout);

if(error !== null)

{

console.log(error);

}

});


D:\node_test>node test.js

 D ����̺��� ����: �� ����

 ���� �Ϸ� ��ȣ: CCEE-4FEA


 D:\node_test ���͸�


2018-09-07  ���� 10:38    <DIR>          .

2018-09-07  ���� 10:38    <DIR>          ..

2018-09-07  ���� 10:35               195 test.js

2018-09-07  ���� 10:38                 0 test.txt

2018-09-07  ���� 10:38                 0 �� �ؽ�Ʈ ����.txt

               3�� ����                 195 ����Ʈ

               2�� ���͸�  916,882,796,544 ����Ʈ ���� 


윈도우에서 euc-kr로 받아서 그런가.. 옵션에 euc-kr encoding 해주어도 깨지는건 여전하네..

어짜피 영어로 주고 받을테니 일단 패스~ ㅠㅠ

[링크 : https://junistory.blogspot.com/2017/08/blog-post_24.html]


+

파일이 ANSI라서 보는데 이런식으로 인코딩 바꾸니 

 hild = exec("type test.txt", {encoding: 'ansi'}, function(error, stdout, stderr)


배쨴다 ㅠㅠ

D:\node_test>node test.js

<Buffer 7b 0d 0a 20 20 20 20 22 6e 61 6d 65 22 3a 20 22 bd c4 bb a7 22 2c 0d 0a 20 20 20 20 22 66 61 6d 69 6c 79 22 3a 20 22 c0 a3 bd c3 c4 da b1 e2 22 2c 0d ... > 


'Programming > node.js' 카테고리의 다른 글

node.js exec와 JSON.parse()  (0) 2018.09.07
node.js express template  (0) 2018.09.06
node.js / express/ pug(jade) 문법  (0) 2018.09.05
npm package.json  (0) 2018.09.05
nodaemon  (0) 2018.09.04
Posted by 구차니