Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(process): Workaround for arguments that contain whitespaces #129

Merged
merged 5 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmds/core/emacs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ exports.builder = async (yargs) => {
exports.handler = async (argv) => {
let _path = UTIL.el_script('core/emacs');

let default_cmd = ['-Q', '-l', _path];
let default_cmd = ['emacs', '-Q', '-l', _path];
let rest = process.argv.slice(3);
let cmd = default_cmd.concat(rest);

UTIL.setup_env();
let proc = child_process.spawn('emacs', cmd, { stdio: 'inherit' });
let proc = child_process.spawn(UTIL.cli_args(cmd), { stdio: 'inherit', shell: true });

proc.on('close', function (code) {
if (code == 0) return;
Expand Down
4 changes: 1 addition & 3 deletions cmds/core/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ exports.handler = async (argv) => {
process.env.PATH = fs.readFileSync(epf, 'utf8');
process.env.EMACSLOADPATH = fs.readFileSync(lpf, 'utf8');;

let program = cmd[0];
let rest = cmd.slice(1);
let proc = child_process.spawn(program, rest, { stdio: 'inherit', shell: true });
let proc = child_process.spawn(UTIL.cli_args(cmd), { stdio: 'inherit', shell: true });

proc.on('close', function (code) {
if (code == 0) return;
Expand Down
6 changes: 1 addition & 5 deletions cmds/core/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ function startCommand(commands, count) {
let command = commands[count];

console.log('[RUN]: ' + command);
let splitted = command.split(' ');

let program = splitted[0];
let rest = splitted.slice(1);
let proc = child_process.spawn(program, rest, { stdio: 'inherit', shell: true });
let proc = child_process.spawn(command, { stdio: 'inherit', shell: true });

proc.on('close', function (code) {
if (code == 0) {
Expand Down
21 changes: 19 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
const path = require('path');
const child_process = require("child_process");

/**
* Form CLI arguments into a single string.
* @param { Array } argv - Argument vector.
*/
function cli_args(argv) {
let result = '';
argv.forEach(function (element) {
// XXX: We wrap double quotes if the string contains spaces
if (/\s/g.test(element)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element = '\"' + element + '\"';
}
result += ' ' + element;
});
return result;
}

/*
* Remove `undefined` item from the array
* @param { Array } arr - target array
Expand Down Expand Up @@ -118,7 +134,7 @@ async function e_call(argv, script, ...args) {
return new Promise(resolve => {
let _path = el_script(script);

let cmd_base = ['-Q', '--script', _path];
let cmd_base = ['emacs', '-Q', '--script', _path];
let cmd_args = args.flat();
let cmd_global = _global_options(argv).flat();
let cmd = cmd_base.concat(cmd_args).concat(cmd_global);
Expand All @@ -133,7 +149,7 @@ async function e_call(argv, script, ...args) {
console.log('[DEBUG] emacs ' + cmd.join(' '));

setup_env();
let proc = child_process.spawn('emacs', cmd, { stdio: 'inherit' });
let proc = child_process.spawn(cli_args(cmd), { stdio: 'inherit', shell: true });

proc.on('close', function (code) {
if (code == 0) {
Expand All @@ -148,6 +164,7 @@ async function e_call(argv, script, ...args) {
/*
* Module Exports
*/
module.exports.cli_args = cli_args;
module.exports.plugin_dir = plugin_dir;
module.exports.def_flag = def_flag;
module.exports.setup_env = setup_env;
Expand Down