最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Command line interpreter for Windows using node.js - Stack Overflow

matteradmin5PV0评论

I'm currently porting some batch files to node.js. I feel more fortable writing in JavaScript but for simple operations like copying a file, instead of:

copy in.txt out.txt

we have to write some more words...:

var fs = require ("fs");
var file = fs.createReadStream ("in.txt");
var newFile = fs.createWriteStream ("out.txt");

newFile.once ("open", function (fd){
    require ("util").pump (file, newFile);
});

If we want to remove a directory and all its content we have to use a recursive function, so 2 simple lines in batch are equivalent to a lot of lines in node.js.

I think that node.js it's so flexible and powerful and you know that windows cmd sucks, so I'm asking here if someone knows a good unix-style mand line interpreter for node.js.

Thanks.

EDIT: I've done a FileUtils library for node.js ->

I'm currently porting some batch files to node.js. I feel more fortable writing in JavaScript but for simple operations like copying a file, instead of:

copy in.txt out.txt

we have to write some more words...:

var fs = require ("fs");
var file = fs.createReadStream ("in.txt");
var newFile = fs.createWriteStream ("out.txt");

newFile.once ("open", function (fd){
    require ("util").pump (file, newFile);
});

If we want to remove a directory and all its content we have to use a recursive function, so 2 simple lines in batch are equivalent to a lot of lines in node.js.

I think that node.js it's so flexible and powerful and you know that windows cmd sucks, so I'm asking here if someone knows a good unix-style mand line interpreter for node.js.

Thanks.

EDIT: I've done a FileUtils library for node.js -> https://github./Gagle/Node-FileUtils

Share Improve this question edited Apr 24, 2012 at 18:18 Gabriel Llamas asked Mar 25, 2012 at 19:26 Gabriel LlamasGabriel Llamas 18.5k26 gold badges90 silver badges117 bronze badges 3
  • 3 To me, this question reads a lot like "I want to use this hammer to drive this screw in." Why not use a shell scripting language (e.g. bash, from Cygwin) to do this? – Thomas Commented Mar 25, 2012 at 19:28
  • Cygwin it's more oriented to provide an environment to pile C/C++ files in Windows and of course it can be used to write unix-style scripts. But I'm asking a specific package for node.js to ease the wokr of moving, copying, deleting, showing the content of a file/directory, creating empty files, etc. with simple mands. It could be an excellent module that so many people will use. I'm just giving ideas... – Gabriel Llamas Commented Mar 25, 2012 at 19:39
  • Well, you asked for a mand-line interpreter, not a filesystem manipulation module. – Thomas Commented Mar 25, 2012 at 19:47
Add a ment  | 

3 Answers 3

Reset to default 4

Thy ShellJS: https://github./arturadib/shelljs

You are using the wrong tools. You would be far better off with BASH or Python. Personally I use Python on systems at work as itis almost ideal for such efforts.

You could try the fileutils package. It's short on documentation, but a quick skim through its source reveals copyFileToFile and copyFileIntoDir functions, and an rm method that recursively removes directories.

Post a comment

comment list (0)

  1. No comments so far