使用node.js的Windows命令行解释器

Command line interpreter for Windows using node.js

本文关键字:命令行 解释器 Windows node js 使用      更新时间:2023-09-26

我目前正在将一些批处理文件移植到node.js。我觉得用JavaScript编写更舒服,但对于复制文件等简单操作,我觉得不太舒服

copy in.txt out.txt

我们得再写几个字…:

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);
});

如果我们想删除一个目录及其所有内容,我们必须使用递归函数,因此批处理中的2个简单行相当于node.js中的许多行。

我认为node.js非常灵活和强大,而且你知道windows cmd很糟糕,所以我在这里问是否有人知道node.js的unix风格的命令行解释器

谢谢。

编辑:我为node.js做了一个FileUtils库->https://github.com/Gagle/Node-FileUtils

你的ShellJS:https://github.com/arturadib/shelljs

您使用了错误的工具。使用BASH或Python会更好。就我个人而言,我在工作中的系统上使用Python,因为它几乎是此类工作的理想选择。

您可以尝试fileutils包。它缺少文档,但快速浏览一下它的源代码就会发现copyFileToFilecopyFileIntoDir函数,以及一个递归删除目录的rm方法。