使用 NodeJs 处理文件系统的新手问题
Newbie issue to deal with the file system with NodeJs
这可能是一个虚拟问题,但我不明白为什么它不起作用。假设我打开一个终端 /home/romu/Musique/Alain Bashung/Compilation 文件夹到 运行 以下命令:
AtomicParsley "01. J'écume.m4a" --artwork ../../cover.jpg
结果是:
Started writing to temp file.
Progress: ======================================================> 99% -|
Finished writing to temp file.
所以它有效。现在,因为我想稍微自动化这个过程,所以我正在编写一个 NodeJs 脚本,它是:
// ES6 only
'use strict';
// Get rid off the first 2 elements of the arguments array,
// First is the path of the node enfine itself
// second is the path of this script
let args = process.argv.slice(2);
// hard coded, will always be those values
let root = "/home/romu/Musique";
let ci = "../../cover.jpg";
let artist = args[0];
let album = args[1];
// Album path
let tracks_path = `${root}/${artist}/${album}`;
const spawn = require('child_process').spawn;
let ap = spawn('pwd', [], { cwd: tracks_path });
ap.stdout.on('data', (data) => {
console.log(`Location: ${data}`);
});
ap = spawn('AtomicParsley', [`"01. J'écume.m4a" --artwork ../../cover.jpg`], { cwd: tracks_path });
ap.stdout.on('data', (data) => {
console.log(`OUT: ${data}`);
});
ap.stderr.on('data', (data) => {
console.log(`ERR: ${data}`);
});
ap.on('close', (code) => {
console.log(`CODE: ${code}`);
});
我得到以下输出:
Location: /home/romu/Musique/Alain Bashung/Compilation
ERR: AtomicParsley error: can't open "01. J'écume.m4a" --artwork ../../cover.jpg for reading: No such file or directory
OUT: AP error trying to fopen "01. J'écume.m4a" --artwork ../../cover.jpg: No such file or directory
CODE: 1
我不知道发生了什么,也不知道为什么它不起作用。任何帮助都会很棒。谢谢
将参数作为数组而不是完整字符串传递。
ap = spawn('AtomicParsley', ["01. J'écume.m4a", "--artwork","../../cover.jpg"], { cwd: tracks_path });
这可能是一个虚拟问题,但我不明白为什么它不起作用。假设我打开一个终端 /home/romu/Musique/Alain Bashung/Compilation 文件夹到 运行 以下命令:
AtomicParsley "01. J'écume.m4a" --artwork ../../cover.jpg
结果是:
Started writing to temp file.
Progress: ======================================================> 99% -|
Finished writing to temp file.
所以它有效。现在,因为我想稍微自动化这个过程,所以我正在编写一个 NodeJs 脚本,它是:
// ES6 only
'use strict';
// Get rid off the first 2 elements of the arguments array,
// First is the path of the node enfine itself
// second is the path of this script
let args = process.argv.slice(2);
// hard coded, will always be those values
let root = "/home/romu/Musique";
let ci = "../../cover.jpg";
let artist = args[0];
let album = args[1];
// Album path
let tracks_path = `${root}/${artist}/${album}`;
const spawn = require('child_process').spawn;
let ap = spawn('pwd', [], { cwd: tracks_path });
ap.stdout.on('data', (data) => {
console.log(`Location: ${data}`);
});
ap = spawn('AtomicParsley', [`"01. J'écume.m4a" --artwork ../../cover.jpg`], { cwd: tracks_path });
ap.stdout.on('data', (data) => {
console.log(`OUT: ${data}`);
});
ap.stderr.on('data', (data) => {
console.log(`ERR: ${data}`);
});
ap.on('close', (code) => {
console.log(`CODE: ${code}`);
});
我得到以下输出:
Location: /home/romu/Musique/Alain Bashung/Compilation
ERR: AtomicParsley error: can't open "01. J'écume.m4a" --artwork ../../cover.jpg for reading: No such file or directory
OUT: AP error trying to fopen "01. J'écume.m4a" --artwork ../../cover.jpg: No such file or directory
CODE: 1
我不知道发生了什么,也不知道为什么它不起作用。任何帮助都会很棒。谢谢
将参数作为数组而不是完整字符串传递。
ap = spawn('AtomicParsley', ["01. J'écume.m4a", "--artwork","../../cover.jpg"], { cwd: tracks_path });