OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/eos/zephyr
[eos/zephyr.git] / server / api / commandExecution / index.js
1 'use strict';
2
3 var express    = require('express'),
4     router     = express.Router(),
5     path       = require('path'),
6     exec       = require('child_process').exec
7
8 router.post('/', function(req, res) {
9     var params     = req.body,
10         command    = params.command,
11         inputPath  = path.normalize('workspace/'+params.inputDir),
12         outputPath = path.normalize('workspace/'+params.outputDir),
13         options    = params.options
14 <<<<<<< HEAD
15
16     var execLine = command
17 =======
18     var execLine = '/Users/hiratakengo/Eos/bin/X86MAC64/'+command
19 >>>>>>> 6b2b2b88511733893d2c6e7848c389abfcd53ba6
20     console.log(execLine)
21     if(options) {
22         options.forEach(function(option) {
23             if(option.isFilled) {
24                 var content = option.content.toString().replace(",", " ", "g")
25                 if(option.name === "-i") {
26                     execLine = execLine+' '+option.name+' '+path.normalize(inputPath+'/'+content)
27                 } else if(option.name === "-o") {
28                     execLine = execLine+' '+option.name+' '+path.normalize(outputPath+'/'+content)
29                 } else {
30                     execLine = execLine+' '+option.name+' '+content
31                 }
32             }
33         })
34     }
35     exec(execLine, function(err, stdout, stderr) {
36         if(err) {
37             console.error(err)
38             res.send('error')
39         } else {
40             console.log(stdout)
41             console.log(stderr)
42             res.send('done')
43         }
44     })
45 });
46
47 module.exports = router