romu
romu

Reputation: 177

Newbie issue to deal with the file system with NodeJs

That's probably a dummy issue, but I can't figure out why it doesn't work. Let's say I open a terminal /home/romu/Musique/Alain Bashung/Compilation folder to run the following command:

AtomicParsley "01. J'écume.m4a" --artwork ../../cover.jpg

The result is:

Started writing to temp file.
Progress: ======================================================> 99% -|
Finished writing to temp file.

So it works. Now, as I want to automate a bit this process, I'm writing a NodeJs script, here it is:

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

I get the following output:

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

I don't know what's going on and why it doesn't work. Any help would be great. Thanks.

Upvotes: 0

Views: 68

Answers (1)

Grasshopper
Grasshopper

Reputation: 1769

Pass the arguments as an array and not the full string.

ap = spawn('AtomicParsley', ["01. J'écume.m4a", "--artwork","../../cover.jpg"], { cwd: tracks_path }); 

Upvotes: 1

Related Questions