Node: child_process.exec does not run alias or a bash function

Created on 19 Nov 2015  路  4Comments  路  Source: nodejs/node

Hey, i have a bash alias on my ubuntu server

myalias="some unix command here"

When running node:

child_process.exec('myalias', {shell: '/bin/bash'},
        function (error, stdout, stderr) {
            console.log('stdout: ' + stdout);
            console.log('stderr: ' + stderr);
            if (error !== null) {
                console.log('exec error: ' + error);
            }
        });

Result with the following error:

_exec error: Error: Command failed: /bin/bash -c myalias_

How can i workaround to run alias or bash function in order to shortcut a long command line.
Thanks in advance!

child_process

All 4 comments

I believe bash only expands aliases when the shell is interactive by default.

any workaround? (except of saving the long command in a .sh file)

@unbalanced It's probably more reliable to actually just call the command you want. If it's too large for that it's probably best to use a shell file anyways.

I wanted it to be a little more modular (and less code/command duplication)
Thanks for the response guys.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yury-s picture yury-s  路  89Comments

feross picture feross  路  208Comments

aduh95 picture aduh95  路  104Comments

mikeal picture mikeal  路  90Comments

speakeasypuncture picture speakeasypuncture  路  152Comments