Obtaining result of process.exec() in SilkJS.

19 views
Skip to first unread message

Eric Dykstra

unread,
Apr 15, 2013, 10:41:34 AM4/15/13
to sil...@googlegroups.com
Hey everyone,

Let's say I have the following SilkJS script;

------------------------------------
#!/usr/local/bin/silkjs

// Some includes ....

function main() {

    var result = true;

    // Some code - that often writes to stdout on error.

    if(there was an error) {
        result = false;
    };

    return result;
}
--------------------------------------

Now, let's say I execute that script from SilkJS with;

var success = process.exec('path/to/the/above/script');

Then, the variable success will contain a string of all the stdout text, and the result.

How do I ONLY get the result back to the SilkJS program that executed the above script?

Thanks,

Eric


Michael Schwartz

unread,
Apr 15, 2013, 10:43:40 AM4/15/13
to sil...@googlegroups.com
The function process.exec_result() returns the return code of the last process.exec() call.  That is, if the program run by process.exec() exits with a value of 125, then process.exec_result() returns 25.

--
You received this message because you are subscribed to the Google Groups "SilkJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silkjs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Eric Dykstra

unread,
Apr 15, 2013, 11:08:28 AM4/15/13
to sil...@googlegroups.com
Mike,

It is always returning 0.

Calling program code segment:

    var command = mPath + '/' + mFileName;
    console.log('command = |' + command + '|');
    process.exec(command);          
    console.log('exec_result = ' + process.exec_result());

Script it is executing:

#!/usr/local/bin/silkjs

function main() {
    return 999;
}; 

Output in console:

command = |/var/www/app/data/migrations/20130414132514296_This_Is_A_True_False_Test.js|
exec_result = 0

What am I doing wrong?

Eric

Michael Schwartz

unread,
Apr 15, 2013, 12:01:18 PM4/15/13
to sil...@googlegroups.com
function main() {
  process.exit(999);
}

You can file an issue on github about the C++ main not exiting with the return value of the JavaScript main()
Reply all
Reply to author
Forward
0 new messages