cexec.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env node
  2. /* vim: set expandtab ts=4 sw=4: */
  3. /*
  4. * You may redistribute this program and/or modify it under the terms of
  5. * the GNU General Public License as published by the Free Software Foundation,
  6. * either version 3 of the License, or (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. var Cjdns = require('../cjdnsadmin/cjdnsadmin');
  17. Cjdns.connectWithAdminInfo(function (cjdns) {
  18. var code = process.argv[process.argv.length-1].replace(/\).*$/, ',cb);');
  19. code = code.replace('(,cb);', '(cb);');
  20. var f = new Function('x', 'cb', 'x.' + code);
  21. f(cjdns, function (err, ret) {
  22. if (err) { throw err; }
  23. console.log(JSON.stringify(ret, null, ' '));
  24. cjdns.disconnect();
  25. });
  26. });